How to Show Product Stock on WooCommerce Cart Page

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 every 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!

See also  Delete Woocommerce Images After Deleting a Product

PHP Snippet: Show Product Stock on WooCommerce Cart Page

 * @snippet       Display Stock @ WooCommerce Cart
 * @how-to        Get FREE
 * @author        Arun Kumar,
 * @testedwith    WooCommerce 4.5
 * @donate
add_action( 'woocommerce_after_cart_item_name', 'codeithub_stock_and_backorder_cart_item_title', 9999, 2 );
function codeithub_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 );

Leave a Reply

Your email address will not be published. Required fields are marked *