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.

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 display out of stock variations as unavailable in WooCommerce

Update

I’ve created a free plugin that will allow you to disable any out of stock variations and even include custom ‘sold out’ text. You can download WooCommerce Better Variations here.

This is a quick solution to how to disable out of stock variations in variation select fields. By default, WooCommerce doesn’t grey out any variations that are out of stock – it allows the user to select the variation first, then lets them know it’s out of stock. Read more

WooCommerce – update product price programmatically

There are many reasons you might want to update a WooCommerce product price programmatically. For instance, in Bookings for WooCommerce the booking (product) price is set dynamically according to certain parameters – e.g. length of stay, etc. In Product Extras, you can specify extra fields for your products (like checkboxes and text fields) which will add extra cost to the product when selected. In this article, I’ll share some simple code to achieve this. Read more

Increase profitability by restricting features

If you are selling WordPress themes or plugins, no doubt you’re always looking for ways to add value to your product and encourage more sales. One common method is to create different plans for your product which limit the number of times a customer can activate it. However, this method can actually reduce your scope to increase your profitability.

In this post, I’m going to show you how you can use the Software Licensing extension for Easy Digital Downloads to make some features of your plugin available only to users on premium plans – and all without having to create and manage different versions of the product. Read more