Display a product’s featured image instead of the variation thumbnail in cart

When you have images linked to individual product variations, the cart will display those variation thumbnails.

Featured Image:


Variation Image:


However, if you want the cart to display the product’s featured image, you can add the following custom code snippet to your child theme’s functions.php file:

// Add this to your child theme's functions.php file
function wc_custom_cart_thumb( $thumb, $cart_item ) {
    return get_the_post_thumbnail( $cart_item['product_id'], 'shop_thumbnail' );
add_filter( 'woocommerce_cart_item_thumbnail', 'wc_custom_cart_thumb', 10, 2 );

How to reorder the fields on a WooCommerce Bookings product

By default, WooCommerce Bookings displays the field of a bookable product in the following order: Duration; Persons; Resource; and the Start Date.

Default Bookings Field Order

If you would like to reorder these fields, simply add the following code snippet in your child theme’s functions.php file:

 * A function to reorder the default display of fields on the WooCommerce Bookings form
 * Put this function in your theme's functions.php file
function custom_order_booking_fields ( $fields ) {

	$reorder  = array();
	$reorder[] = $fields['wc_bookings_field_duration'];  // Duration
	$reorder[] = $fields['wc_bookings_field_resource'];  // Resource
	$reorder[] = $fields['wc_bookings_field_persons'];  // Persons
	$reorder[] = $fields['wc_bookings_field_start_date'];  // Calendar or Start Date

	return $reorder;
add_filter( 'booking_form_fields', 'custom_order_booking_fields');

By changing the line order in the function, you control the order in which they display on the front end of the bookable product.

Reordered Bookings Fields

Note: If you are using Person Types, this code will not work to display the different types.

How to set a custom URL for the Continue Shopping button in the Cart

When you set WooCommerce to automatically redirect to the Cart when a customer adds a product to their cart, a Continue Shopping button appears on the page.

Continue Shopping Button

By default, the Continue Shopping button redirects the customer back to the product page that had just been added to the cart. If you’d like the change that redirect link, add the following code snippet to your child theme’s functions.php file:

 * Redirect the Continue Shopping URL from the default (most recent product) to
 * a custom URL.
 * Place this code snippet in your theme's functions.php file.
function custom_continue_shopping_redirect_url ( $url ) {
	$url = "http://www.woothemes.com"; // Add your link here
	return $url;
add_filter('woocommerce_continue_shopping_redirect', 'custom_continue_shopping_redirect_url');

I hope that this helps!

How to display “Low Stock” instead of “Only x left in stock” on product page

Only x left in stock

If your product page displays the total number of inventory available once it reaches the Low Stock Threshold, there is a way to change that phrase to simply read “Low Stock”.

Add the following code snippet to your child theme’s functions.php file:

/* Change the 'Only # left in stock' message on the WooCommerce product page to
 * simply show 'Low Stock'.
 * Add to your theme's functions.php file
function custom_stock_totals($availability_html, $availability_text, $product) {
	if (substr($availability_text,0, 4)=="Only") {
		$availability_text = "Low Stock";
	$availability_html = '

‘ . esc_html( $availability_text ) . ‘

‘; return $availability_html; } add_filter(‘woocommerce_stock_html’, ‘custom_stock_totals’, 20, 3);

This is the result:

Low Stock

This solution assumes that your store is using the Stock Display Format as follows:

Stock Display Setting

How to Disable a Payment Method in Checkout for Certain Products

Sometimes, you don’t want to offer a particular payment gateway in your WooCommerce checkout if a customer has a certain product in their cart.

Here’s a code snippet that you can add to your child theme’s functions.php file to help:

 * Disable PayPal payment method in the checkout if certain 
 * products are present in the cart.
 * Add this to your theme's functions.php file
add_filter( 'woocommerce_available_payment_gateways', 'filter_gateways', 1);
function filter_gateways( $gateways ){
  global $woocommerce;
  foreach ($woocommerce->cart->cart_contents as $key => $values ) {
    // store product IDs in array PayPal method is disabled at checkout
    $nonPPproducts = array(1111,2222,3333);		// LIST YOUR PRODUCTS HERE

    if ( in_array( $values['product_id'], $nonPPproducts ) ) {	
      // You can unset other gateways using the gateway ID e.g. "cod", "bacs", "stripe"
  return $gateways;

You simply have to add the product(s) by their ID to the array list. If you want to disable other payment methods, you can find their Gateway ID under WooCommerce > Settings > Checkout:

Payment Gateway ID WooCommerce