The WooCommerce stock status (In Stock, Out of stock) will only show if WooCommerce is managing the stock for you. I was working on a project and the client wanted the ability to manually set if the product was in stock or not. The code snippet below will allow you to show the stock status for both managed and unmanaged products. Just copy and paste into your themes functions.php file.
// Show the status for unmanaged stock products
add_filter( 'woocommerce_get_availability', 'show_stock_status_for_unmanaged_products', 1, 2);
function show_stock_status_for_unmanaged_products( $availability, $_product )
// Don't do anything if managing stock
if($_product->managing_stock()) return $availability;
$availability['availability'] = __('In Stock', 'woocommerce');
$availability['class'] = '';
$availability['availability'] = __('Out of Stock', 'woocommerce');
$availability['class'] = 'out-of-stock';
I’ve always found it annoying that you can’t set a different ul bullet colour through CSS. It should be as simple as:
Read more on “Setting a different ul bullet colour in CSS” »
Have you just updated your local of WordPress and its now all broken on MAMP, I’ve had this problem a few times now so thought it would be worth sharing how to fix this. The problem is caused by the load-scripts.php file being compressed with zlib, I first did as suggested on this stackoverflow question. But this still didn’t fix the problem after some looking around I noticed that MAMP zlib compression was turned off, when I turned this on WordPress worked fine. I’m not sure why this would fix it as zlib will only send compressed data if the browser lets apache know through the headers. I have a feeling this could be a bug with Chrome, or Mamp sending compressed data when the browser is not expecting it.
To fix this problem you will need to open /Applications/MAMP/conf/php5.4.4/php.ini in your text editor of choice, then search for zlib and you should find the line below.
zlib.output_compression = Off
You just need to change this line to
zlib.output_compression = On
Then just restart apache with apachectl restart and hopefully everything should be working again for you.
NOTE: After taking these steps I installed a new copy of WordPress and had the problem again, after restarting apache again the problem went away.
As a web developer you learn that there is nothing more important than keeping regular backups of your databases. I’ve created a little bash script to help with Backing up MySQL databases for this I’ll use mysqldump. Mysqldump is a nifty little utility that lets you dump the contents of a database to a file, so I use this to create a little bash script that will backup the database at regular intervals, and I’ll even chuck in deleting backups older than 30 days so you don’t over run with files.
First lets state the obvious security warning here, this script will contain details of your database so make sure you set the correct permissions, I use 700 but this may change depending on your hosting provider. Also don’t place the backup folder in your public_html folder otherwise people will be able to see the contents of your database and again lets make sure the .sql have the correct permissions otherwise over users on your server will be able to access them. Read more on “Backing up MySQL Databases” »
I’ve found that one of the best parts of putting my site live in May earlier this year, was being able to start again and use what I had learnt to improve my site. Today I have launched my new design and I couldn’t be happier with it.
I think as a web developer/designer it’s easy procrastinate to much over your own site. When we work on a site for a client we have a specification and deadline to meet so the process is much simpler as you know what you need to deliver and when. Read more on “Website relaunch” »
The other day I found myself needing to insert into an array at a given position, so I wrote this little function. For example if you have pulled a list of posts from a database and are going to loop through these to output the HTML, but want to insert an advert after the third post, you can simply insert into an array at the third position.
The function is pretty simple and takes 3 parameters, the existing array $array, the data to be inserted $var and the position $position. The function then splits the array in two at the given position and merges the first array with the data and then merges again with the 2nd array. The function converts the data to be inserted to an array so you can pass any data type.
function array_insert($array, $var, $position)
$before = array_slice($array, 0, $position);
$after = array_slice($array, $position);
$return = array_merge($before, (array) $var);
return array_merge($return, $after);
You can also see view the gist.
After my laptop has been running really for a couple of weeks now, I have decided to order some new RAM and do a clean install of Lion. This has given me a great opportunity to configure my development environment in a cleaner and more organised way.
As a developer I do install a number of packages to play around with and then either decide its not for me or find there was a better way configuring them and then find myself in a bit of a muddle. Read more on “Using composer with MAMP’s version of PHP” »
I’ve been playing with Ruby on Rails recently and I’ve been using Pow as a rack server for the applications I’m working on. So I don’t have to keep running “rails server” when I want to test an app out. It’s a brilliant little tool from 37 Signals that they describe as a zero-config rack server and it is just that.
The only drawback to Pow is that it highjacks all localhost requests, this means that working with MAMP and Pow simultaneously can be tricky. The easiest and simplest solution would be to leave the MAMP port for apache to the default 8888 so you can access your htdocs folder from http://localhost:8888/ Read more on “Using MAMP and Pow on the same machine” »
I just came across a free eBook called Locking Down WordPress from CodePoet featuring Rachel Baker, Brad Williams, and John Ford. It’s an interview style book asking the 3 pro’s how they handle security for their sites and is a must for anyone who uses WordPress for their clients as it will save headaches later on!
This week I learnt an important lesson when using Search and replace in WordPress. When I’m working on a site in development I have WordPress running on a dev domain so the client can view the website and make any changes via the dashboard. When the site is ready to go live I go about transferring the domain. To do this I also need to update any posts in WordPress that may contain the old dev domain to the new live one.
To do this I use a plugin by Bueltge called Search and replace. This searches your database for a string of text and replaces it with another, which is perfect for replacing old dev URL’s for live URL’s I have used this numerous times in the past and never had any problems with it. Read more on “The dangers of search and replace in WordPress” »