Adding a Section to a Settings Tab

I published this over in the WooCommerce Developer Docs the other day. Please keep it in mind if you’re developing an extension for WooCommerce – along with the Create a WooCommerce Plugin guide.

When you’re adding building an extension for WooCommerce that requires settings of some kind, it’s important to ask yourself: Where do they belong?

If your extension just has a couple of simple settings, do you really need to create a new tab specifically for it? Most likely the answer is no.

Continue reading Adding a Section to a Settings Tab

Only Show Free Shipping When it’s Available in WooCommerce

There is an awesome doc in our WooCommerce documentation that explains just how to do this, but it’s often missed / hard to find, so I’d like to write it a little bit about it here.

If you have free shipping on your WooCommerce site but only offer it in certain situations, like when the total order amount is above $100, you probably don’t want to show the other paid shipping methods.

I mean, what kinda customer is going to pay for shipping when you’re offering it to them for free? It makes more sense just to hide those paid options when free shipping is available. If you add the following code to the ‘custom functions’ area of your functions.php file (or use a plugin like Functionality), it will do just that (WooCommerce 2.1+ required):

Delete the php first line if you are having errors come up after saving the file.

But wait! Is that too confusing above? Instead, just download and install the following plugin: WC Only Show Free (.zip)

Change WooCommerce ‘Ship to a different address?’ Default State

You may want to change how the extra shipping address fields in the WooCommerce Checkout are shown.

By default, they tend to be hidden but you can ‘check’ a checkbox to show them and ship to a different address.


However, you may want to keep this open by default. To do so, add the following code to the ‘custom functions’ area of your functions.php file (or use a plugin like Functionality –

To Enable:

add_filter( 'woocommerce_ship_to_different_address_checked', '__return_true' );

To Disable:

add_filter( 'woocommerce_ship_to_different_address_checked', '__return_false' );

There’s an interesting discussion over this that took place over a year ago that you can find in WooCommerce Issue #2571.

Open ‘Calculate Shipping’ Box on WooCommerce Cart Page Load

I’ve seen this request a couple times while helping out WooCommerce customers so I thought I’d share a quick CSS snippet that will do just that.

Add the following to your custom.css file or with a plugin like Simple Custom CSS:

.shipping-calculator-form {
    display: block !important;

This will make the Calculate Shipping box automatically open when the Cart page is loaded.

Add PDF to WooCommerce Order Email

Quick little snippet that will let you add a static PDF file (or in fact, any kind of file) to the WooCommerce Order Emails.

Just add the following code to the ‘custom functions’ area of your functions.php file:

Delete the php first line if you are having errors come up after saving the file.

Now simply edit the $your_pdf_path variable to be wherever your PDF (or other file) is located!

Too easy, right?


Filter WooCommerce Admin Orders by Individual Dates

WooCommerce comes with the handy ability to filter your orders in the admin by the month they were made.

Screenshot on 2014-07-22 at 13-50-13

However, you may want to filter them for a specific date or date range.

This doesn’t come standard in WooCommerce but can actually easily be achieved by using an awesome free plugin, Posts Date Range.

Simply install it and voilà… you can sort those orders as you please!

Screen Shot 2014-07-22 at 1.52.44 pm

Order Products by ‘On Sale’ in WooCommerce

Have you ever wanted to place your on sale items at the top of your product listings? You can pretty easily do it in a couple of ways.

Screen Shot 2014-07-14 at 3.51.59 pm

If you would like to add a ‘On Sale’ option to the ‘orderby’ menu, so users can choose to order it themselves, add the following code to the ‘custom functions’ area of your functions.php file:

However, if you would like to make it the default order, add this:

I hope that helps you out!

Change the WooCommerce Auto Generated Password

In WooCommerce, there’s a setting under WooCommerce > Settings > Accounts to automatically generate a customer’s password. This way user’s only have to enter an email when they register (with the password generated and sent to their email address), similar to how WordPress handles registration by default.

WooCommerce uses WordPress’ core wp_generate_password() function to generate the password, but you may want to change this.

You can do this by filtering woocommerce_new_customer_data, declared around line 102 of woocommerce/includes/wc-customer-functions.php:

So, if for example you wanted to make the password generate as the user’s email, you could use the following:

Or perhaps you want to use the wp_generate_password() function but customise it a little bit, so that it’s only 6 characters and uses all special characters. Something like this would work:

If it helps you out or you were able to customise and make something even more awesome, let me know!