WooCommerce – show “In stock”, “Out of stock”, “On Backorder” text on products

Content Views Pro helps you to show WooCommerce products in grid and list layout easily.
You might want to show in stock, out of stock, on backorder status for your products.
To do that, please add this code to file functions.php in the theme’s folder (or install this plugin Code Snippets then add this code to the “Code” textarea):

// Content Views Pro - Woocommerce: Display product status
add_action( 'pt_cv_item_extra_html', 'cvp_item_extra_html_wofs' );
function cvp_item_extra_html_wofs( $post_id ) {
	$product = wc_get_product( $post_id );
	if ( is_object( $product ) ) {

		// Out of stock
		if ( !$product->is_in_stock() ) {
			echo '<div class="out-of-stock">Out of stock</div>';
		}

		// In Stock
		if ( $product->is_in_stock() ) {
			echo '<div class="in-stock">In stock</div>';
		}

		// On Backorder
		if ( $product->is_on_backorder() ) {
			echo '<div class="on-backorder">On Backorder</div>';
		}

	}
}

Best regards,

Scroll to Top