Gerhard Potgieter

WordPress / WooCommerce Engineer at Automattic

WooCommerce Custom Product Fields — September 17, 2013

WooCommerce Custom Product Fields

In this WooCommerce tutorial I will be showing you how to add a custom field to a WooCommerce product.

I will go through adding a custom field on the general tab section of the WooCommerce edit product page underneath the price fields where you can enter a value in to be saved, go through saving and validating the data and then displaying the data that was saved on the product page on the front-end of your shop.

As an example I will be showing you how to add a Recommended Retail Price (RRP) to a WooCommerce product and display this on the front-end, so lets get starting.

First step would be to define the field on the edit product page, luckily WooCommerce makes this very easy due to the large array of hooks available for use as well as the built in functions to generate HTML input fields. Place the following code inside your theme’s functions.php file to define a new text field on the product edit page.

You will now have a field on your product edit page called RRP, however if you enter something into the field and save the product, the data will not be save as we need to actually still save the data when the product gets updated, to save it and also check that a numeric value is entered add the following code to your theme’s functions.php file

Now when you enter a value in the RRP field and update the product the field should be saved and loaded in the RRP field you defined when the page loads. The final step would be to actually display the value saved on the product page on the front-end for customers to view, to do this add the following code to your theme’s functions.php file

Your end result will look like the image below when you add or edit a product

WooCommerce Custom Product Field Backend

And will look like this on the front-end when a customer views the product

WooCommerce Custom Product Field Front-End

Just a note that this tutorial does not cover adding custom fields to variable product, that process is covered in this tutorial by my fellow team member at WooThemes, Remi Corson.

WooCommerce Product Quantity Dropdown — September 9, 2013

WooCommerce Product Quantity Dropdown

WooCommerce Quantity Dropdowns

WooCommerce by default adds a quantity input box to your product pages where customers can enter quantities, but a lot of times you want to have more control over the quantities and make it more idiot proof on your site for customers by allowing them to select the quantities instead of entering it themselves.

The following snippet of code I wrote will replace the default WooCommerce quantity input box and replace it with a dropdown select option of quantities. It is fully compatible with the Min/Max Quantities extension which allows you to display quantities in the dropdown based on the minimum, maximum and group values so the customer can only select values in which the product can be bought instead of having to use plus and minus buttons or entering a value manually.

To turn your WooCommerce quantity input boxes into dropdown select options simply copy the following code to your theme’s functions.php file

WooCommerce Product Image Slideshow Using WooSlider —

WooCommerce Product Image Slideshow Using WooSlider

WooSlider Product Image Slideshow

At WooThemes we have this cool plugin called WooSlider which basically allows you to create awesome sliders just about anywhere on your site, it is a powerful WordPress slideshow plugin yet simple to use.

One of the questions that has been popping up a lot lately in support is, how can I turn my WooCommerce product images on the single product page into a slideshow instead of displaying a normal image, well luckily with WooSlider this is a breeze to do.

You simply need to purchase and install WooSlider, then you need to place the code below into your theme’s functions.php file

Deploy From Github To Plugin Repo — September 8, 2013

Deploy From Github To Plugin Repo

Deploy straight from Github to WordPress Plugin SVN Repository

Lately I have been working on quite a few WordPress plugins that are hosted in the plugin repository, and since Github is my go to version control system, I like it a lot and we use at WooThemes as well, I got a bit fed up with having to keep a local SVN copy and doing things manually.

After some googling I eventually found a bash script that enables you to deploy directly from your Github repository without the need to keep a local copy of the SVN repository, it is as simple as adding the script below to your Github repo, changing a few lines in the script and then executing it when you want to deploy to the plugin repository/

I take no credit for this script, in fact it was created by a fellow WooCommerce plugin developer, Brent Shepherd, he developed and maintains the awesome WooCommerce Subscriptions extension.

To deploy straight from your Github repository to your Plugins SVN repository, simply copy the bash script below and place it in a new file in your Github repository, I use, once the file is there you can commit it to Github so it is always part of your plugin, then open up the file and edit the following parameters.

PLUGINSLUG – Change this to the slug of the plugin on
MAINFILE – Change this to the main PHP file that contains the WordPress version number of the plugin
SVNUSER – Change this to the username of the user who owns the plugin, it will be commit under this user.

And that is it, once you have modified the file, you will have to make it executable by (chmod u+x it via terminal, then when you are ready to deploy it, go to your Github repository where you stored the file and run the following command via terminal ./

It will ask you a few questions along the way and do some checks as well as tag the version on Github for you.

WooCommerce Percentage Saved Sale Price — September 6, 2013

WooCommerce Percentage Saved Sale Price

WooCommerce Percentage SavedWhen you have items on sale in WooCommerce, by default WooCommerce will display the regular price striked out with the sale price next to it.

Why not take it a step further and show your customers the savings they are getting on the sale price, with this snippet of code you can easily display the percentage saved next to the price of items on sale in WooCommerce.

Place the code below in your theme’s functions.php file

WooCommerce Change Description Tab Title & Heading To Product Name — September 4, 2013

WooCommerce Change Description Tab Title & Heading To Product Name

WooCommerce Product Title as Description Tab title and heading

So as promised I will do a lot more posts on this blog and to kick things off I am doing a snippet on how to change the WooCommerce single product description tab title and heading to that of the product name instead of just saying Description.

To change the WooCommerce Single Product Description tab title and heading to the product name, place the following PHP code in your theme’s functions.php file

Hello WordPress — September 3, 2013

Hello WordPress

[Insert customary introduction speech here.]

Okay let me not bore you with that, instead I am going to keep it short and simple. Three years after registering this personal domain I have finally decided to dedicate more time to actually work on this site and make an effort to blog on a regular basis here.

I’ll try my best to blog at least once every week or two on things related to WordPress, most specifically keep an eye out for all sorts of tips, tricks and tutorials on WooCommerce.

Who am I you ask? I am Gerhard Potgieter, a web developer from Cape Town, South Africa. I work for one of the most awesome WordPress centric companies out there, WooThemes, where my main duty is to provide first class WooCommerce support to our customers, I also development WordPress plugins and WooCommerce extensions on a regular basis.

Little bit about the setup I have here, obviously I am running WordPress, duh. The theme is PixelPress by WooThemes, which I modified a bit via a child theme.

%d bloggers like this: