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.

Checkout___W

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 – https://wordpress.org/plugins/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?

Reference: http://wordpress.org/support/topic/pdf-attach-terms-and-conditions-to-email

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!

How to Fix the WooCommerce Quantity Field in Firefox

As I’ve been settling into my new position as a WooCommerce Support Ninja at WooThemes, I’ve been seeing the following issue appear for some users in Firefox.

It’s important to note, that this is not actually an issue with WooCommerce, but often caused by Javascript conflicts/errors on one’s site.

You may notice an issue with the quantity field on a product’s page, where a user can’t use the jQuery number input form. It seems to be just another set of up/down arrows inside of the text box, with no ability to actually write a quantity number.

If you’re having trouble solving the Javascript problem (you should solve it), and you’re too lazy to get help and fix it (really, you should fix it), you can add the following to your custom.css / style.css file or with a plugin like Simple Custom CS.

I hope that helps you out!

Check if Another WordPress Plugin is Active

Recently I’ve been spending a lot of time working on my new plugin Recipe Hero. Essentially, the plugin is an open-source, free item, but the extensions that I (and others) make for it, can be either free or premium.

Similar to WooCommerce, Easy Digital Downloads, WP Job Manager and even WordPress itself, the core item itself is a simple, sufficient plugin, but the functionality to take it that little bit further and do something ‘out of the norm’, should be in its own separate ‘extension’ or ‘add-on’.

However, what if a user doesn’t realise that and tries to add an extension without the ‘core’ plugin? Or how about when a user deactivates the core plugin but forgets about deactivating the extensions. We need to put a check in for that or you’re going to be dealing with some angry users.

WooCommerce actually has a great article on Creating a plugin for WooCommerce, that gives it a great example of how to check for another plugin. A lot of people like to use is_plugin_active, but I like WooCommerce’s method better, as is_plugin_active is a little bit less flexible. Themergency also has a post looking at different methods to check if a plugin is active.

The approach WooCommerce takes is to check if the woocommerce/woocommerce.php file is in the array of active plugins, using PHP’s in_array function.

So if we wanted to check if WooCommerce was active, they suggest to use the following:

In a Recipe Hero extension, Recipe Hero Likes, I need to check if Recipe Hero is active before requiring a couple files that contain most of the extension’s functions. The following is what I use:

How do you like to check if a plugin is active? Do you think there’s an issue using in_array? Let me know in the comments!

Introducing Recipe Hero

I’ve been working on something close to my heart for the past few weeks. It’s called Recipe Hero and it’s going to change the way we eat food.

UPDATE: Website’s Up!

Okay, that’s a little much.

banner-772x250

It’s pretty much just a new WordPress plugin for easily adding recipes to your WordPress site. It has a lot of neat features packed into it, from automatic schema.org mark-up to its own template engine.

I wanted to make it as easy possible for WordPress users to share their amazing food, and I feel like Recipe Hero will do just that.

It’s available now for free on the WordPress.org Plugin Repository.

I’ve got a lot of awesome stuff planned for it. In the next few weeks I’m hoping to move it out of beta into Version 1.0.0 (we’re at 0.6.7 at the time of writing). I’m building the website too at the moment, trying to get all the documentation and a few add-ons ready for it too.

It’s also a completely open-source, GPL-licensed project, and I would love for you to stop by the GitHub Project and contribute in any way you can.