We’ve already seen how to display stock quantity and status on the Shop Page – today we’ll do something similar, but this time we’ll work on the Cart product table, so that we can visually display stock status and quantity to WooCommerce customers who are about to checkout.

Please note – in order for the snippet to work you must have “stock management” enabled, and also each single product in the cart must have “managing stock” checked and, if on backorder, “allow but notify customer” must be selected, otherwise you will see nothing. Enjoy!

The final result after using the snippet below: each product also displays its stock status and stock quantity.

PHP Snippet: Show Stock @ Cart Items

/**
 * @snippet       Display Stock @ WooCommerce Cart
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli, BusinessBloomer.com
 * @testedwith    WooCommerce 4.5
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_action( 'woocommerce_after_cart_item_name', 'bbloomer_stock_and_backorder_cart_item_title', 9999, 2 );

function bbloomer_stock_and_backorder_cart_item_title( $cart_item, $cart_item_key ) {
	$product = $cart_item['data'];
	if ( $product->backorders_require_notification() && $product->is_on_backorder( $cart_item['quantity'] ) ) return;	
	echo wc_get_stock_html( $product );
}
Share:

Leave a Reply