I recently discovered WC_Order_Query
, which is essentially WooCommerce’s version of WP_Query
but specifically for orders. Read more
Blog
Create a popular posts shortcode in WordPress
This is a useful way to display popular posts on your blog to encourage users to read more articles rather than just bounce away. Read more
How to change position of ‘Add to Wishlist’ button in WooCommerce Wishlists
If you’re using WooCommerce Wishlists, you might want to change the position of the ‘Add to Wishlist’ button in the single product template.
To do this, you just use the woocommerce_wishlists_template_location
filter:
function prefix_wishlist_template_location( $template_hook, $product_id ) { | |
// Return your hook here | |
return 'woocommerce_single_product_summary'; | |
} | |
add_filter( 'woocommerce_wishlists_template_location', 'prefix_wishlist_template_location', 10, 2 ); |
Just substitute whichever hook you want to call the button on.
Product Extras for WooCommerce version 2.0
Version 2.0 of Product Extras for WooCommerce has been released today. Read more
Override WooCommerce template from your plugin
While doing some custom work for a client, I found that I needed to override a WooCommerce template from within a plugin. The client wanted to add some additional columns to the cart table and, as the WooCommerce cart.php
template is not as hookable as most of the rest of WooCommerce, the only option was to override the template.
The normal way to do this is to include your new template file in the child theme. Usually this would be absolutely fine but in this instance the client wasn’t using a child theme and switching to one would have meant laboriously updating the theme settings. So the alternative was to include a version of cart.php
within the plugin I was developing.
/** | |
* Filter the cart template path to use our cart.php template instead of the theme's | |
*/ | |
function csp_locate_template( $template, $template_name, $template_path ) { | |
$basename = basename( $template ); | |
if( $basename == 'cart.php' ) { | |
$template = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'templates/cart.php'; | |
} | |
return $template; | |
} | |
add_filter( 'woocommerce_locate_template', 'csp_locate_template', 10, 3 ); |
All we do is use the woocommerce_locate_template
filter, check the name of the template – in this case cart.php
– and replace the template path with a path to our own file.
Note that this code uses plugin_dir_path( __FILE__ )
to generate the path to the file, so you’ll need to fire this function from the plugin’s root directory.
How to build a ‘create your own pizza/sandwich/meal’ product in WordPress
This article is a ‘use case’ for the Product Extras plugin, showing you how to build a ‘create your own pizza’ type product in WordPress, using WooCommerce and Product Extras. We’ll build an example product that would allow customers to configure their own pizza, specifying their choice of base, sauce, size and toppings. Read more
Flat rate product add-ons in Product Extras
Version 1.7.0 of Product Extras is now live and it brings a much-requested feature: flat rate pricing. Flat rate pricing is the ability to apply pricing for WooCommerce product add-ons only once, whatever the quantity of product selected. You can enable flat rate pricing for any options that do not multiply with product quantity. Read more
Product Extras: global add-ons
The latest version of Product Extras sees the implementation of global extras, meaning you can now create a group of add-on fields and apply it to all, or some, of your products.
How to add custom fields to a WooCommerce product
In this post, I’m going to walk through the entire process of adding custom fields to a WooCommerce product. Custom fields (also called product addons) include text fields, select fields, checkboxes, and so on. They allow the user to enter additional, personalised information about a product. The post will cover creating and displaying the custom fields, adding the custom field data to the cart, and inserting the data in emails and orders. Read more
How to add a custom field to a WooCommerce Subscriptions variation product
There may come a time in your life when you’re working with WooCommerce and WooCommerce Subscriptions and you realise that you need to add a custom field to a variable subscription product. Admittedly, most people will live their entire lives without encountering this need but if you’re one of the few who do, then hopefully this article will help. Read more