How to Show Product Stock at Cart Page in WooCommerce?

The stock status and stock quantities provide more information to WooCommerce customers. It can create an urgency for customers to buy products right away and not bounce back. This in turn can encourage sales to your ecommerce store. So, in this article, you will learn how to show product stock at cart page in WooCommerce. You can display these data on the cart product table when customers are about to checkout.

Furthermore, you should activate the following things to make this function work. You must enable ‘stock management’. Also, you need to enable ‘managing stock’ for every single product at the cart. If you will restock the product in the near future, then you must select ‘allow but notify customer’. Otherwise, you cannot enable this function. 

Image describing how to show product stock at cart page in WooCommerce

PHP Snippet: Show Product Stock at Cart Page in WooCommerce

add_action( 'woocommerce_after_cart_item_name', 'phpsof_stock_and_backorder_cart_item_title', 9999, 2 );
 
function phpsof_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 );
}

Where do you add this snippet?

So, this is how you can show product stock at cart page in WooCommerceAlso, it is easier to activate this function with this code. So, to apply this code, just add this PHP snippet at your child theme function.php file’s bottom. It should be placed before “?>”, if you have it there. Apart from this, CSS goes in your child theme style.css file. Make sure that you are editing these files in a right manner for best results.

Is this snippet still valid?

So, this is how you can learn about show product stock at cart page in WooCommerce. I have applied this code on the Storefront theme and WordPress friendly hosting PHP 7.3. Let me know if everything works as expected when you code. Share it further if you find this snippet useful for you and it had saved your time. 

Also Read, How to Move Email Field to Top in WooCommerce at Checkout Page?

How to Conditionally Force Product Quantity 1 at Cart in WooCommerce?

Important links: WooCommerce – https://woocommerce.com/