A few months ago I wrote a post on how to add custom fields to WooCommerce products within the administration, and many of you ask me how to add custom fields to products variations. So I decided to write this tutorial to help you create new fields for each WooCommerce product variation. The final result of this tutorial will look like this:
In WooCommerce <= 2.0.20, searching products by SKU in the administration used to be done using the “SKU:” prefix, but this was removed in version 2.1. You can now search by SKU without having to add the prefix in the search form. However there’s a little bug in versions 2.1, 2.1.1 and 2.1.2 in the function that returns only one single result while it should return all products having a SKU starting by a same prefix. This should be fixed in version 2.1.3, or 2.1.4.
As a temporary fix you can add this snippet to the functions.php file in your theme folder:
And then use the old search method (eg. “SKU: 7810″ will return all products having the SKU starting by 7810).
Sometimes when providing support for WooCommerce at WooThemes we have strange requests, and I got one recently that i wanted to share. It was about the orders date format in the administration. The default format is Y/m/d, and the customer wanted it to be d/m/Y. How to achieve this? Well, simply by using a filter and little function, here is the code to paste in functions.php in the theme folder to make this change:
And here is the result:
WooCommerce provides a nice feature that force your customers to accept your terms and conditions if you define the corresponding page within WooCommerce settings. If your customers don’t check the “terms and conditions”, they can’t proceed the order. This is nice and easy to setup.
Setup the Terms & Conditions Page
Just a quick reminder on how to set this up. First of all, create a new page, call it “Terms” (or what you want!), add your content, then go to WooCommerce > Settings > Checkout in WC 2.1.x or to WooCommerce > Settings > Pages for versions below 2.1. Then choose the page you just created in the corresponding dropdown select and save settings.
And here is what your customers will see on the checkout page:
That’s pretty neat right? But what happens when one your customer has a litigation with you? Can you prove that your customer accepted your terms and conditions? The answer is not that simple. You can still say that it’s impossible to purchase on your site without accepting your terms and conditions, but legally, it is not enough.
The solution, is to add a snippet to your site that will store the “terms and conditions” field value within the database, and in that case you can prove that terms and conditions were accepted, order by order.
Simply add this code to the functions.php file within your theme folder:
This code will store the field value within the database, and will also print this information on the “edit order” page:
Since WC 2.1, some shortcodes in WooCommerce have been removed and replaced by endpoints. That means that some shortcodes aren’t valid anymore. Basically if you go to WooCommerce > Settings > Accounts tab, you will be able to view and edit endpoints values. Let’s say your “my account” page slug is “my-account”, then all pages will be reachable using this structure:
For the logout page it would be http://mysite.com/my-account/customer-logout
So, why did we choose to replace shortcodes by endpoints?
Well, WooCommerce is used by many non technical persons that can easily break it. In former WooCommerce versions, you had to create pages, create a link between those pages and WooCommerce settings, and add shortcodes to the newly created pages. That was too much, and too many risk to break the site. Now endpoints, give a really simple way to deal with custom urls and WooCommerce pages, without the risk of having a page without a shortcode that wouldn’t display anything.
How to add WooCommerce specific URLs to the WordPress menu
To add WooCommerce pages URLs to your WordPress main menu, simply go to Appearance > Menus in the WordPress main menu:
Then click on the links section:
And finally add custom URLs using the “my account” page slug and the endpoints values, and hit the add to menu button: