A simple, powerful and independent e-commerce platform.
Sell anything with ease.

Display ‘Out of stock’ on category pages

If an item is out of stock there is no indication of this on the category page. Customers need to visit the individual product page to discover the availability. This code adds a line to the category page to say an item is out of stock. Change the message if you prefer “Sold out” or some other term. A css class called .out-of-stock has been included to allow for customising the styling.

		/**
 * Display 'Out of stock' on category pages
 */

add_action('woocommerce_before_shop_loop_item_title', 'cc_display_out_of_stock_in_loop');

function cc_display_out_of_stock_in_loop() {
  global $product;

  if ( !$product->is_in_stock() ) {
  echo '<span class="out-of-stock">' . __('Out of stock', 'woocommerce') . '</span>';

  }
}
	
View Raw Code ID: 9991