How to Show Product Stock on the Cart Page WooCommerce

WooCommerce Show Product Stock on the Cart PageDo you want to display the stock text on the WooCommerce cart page? Then stick to the end, as this post aims to provide you with a simple solution to this problem. By default, in stock or stock availability, the text is not shown by default on the Storefront theme, and you may want to show this text on the cart page.

When publishing a product in WooCommerce, it is possible to set the stock status. If you want to change this text, you can refer to this tutorial.

The stock availability text in WooCommerce can be out of stock, backorder, or in-stock status. It is important to note that these statuses can be set for each WooCommerce product under the inventory tab.

To display this text on the cart page, you need to add a filter to your themes functions file to display it. This is because WooCommerce does not display this text on the cart page.

The best approach to display stock availability text on the cart is to combine both the in-stock and out-of-stock text in one filter and display them conditionally.

WooCommerce Show Product Stock on the Cart Page

By the end of this post, you will be able to display the product stock on the cart page. We will discuss each step in detail to help you implement the solution effectively.

Before you proceed, you need to create or install a child theme. This means that you need to install or create a child theme to ensure your changes are not lost during an update.

Let us get right into it.

Steps to Show Product Stock on the Cart Page

Here are the simple steps you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file to add the function to show the product stock on the cart page.
  3. Add the following code to the functions.php file:
[php] add_action( ‘woocommerce_after_cart_item_name’, ‘njengah_stock_and_backorder_cart_item_title’, 9999, 2 );
function njengah_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 );
}
[/php]
  1. This is the outcome:stock cart

Wrapping Up

In this brief tutorial, we have shared how you can display the inventory level on the cart page for all the products in your store. By default, WooCommerce allows you to manage inventory levels, but you cannot display them on the cart page. This is why we have created this solution to help you out.

If you are not familiar with handling code, we recommend contacting a qualified WordPress developer. This will ensure that your changes are not lost during an update.

Similar Articles