skip to Main Content

Currently, our customers checked on their list of products added on cart like sometime ago and notice that 2 or 3 products are gone as it turns out, the product is out of stock.

Default functionality: Remove products on the shopping cart once it is out of stock.

We have our store set so that when an item is out of stock, a customer cannot add it to their cart. However, if an item is added to a cart and then goes out of stock before that customer checks out, the client want the product not deleted in the list under cart page but add a text "out of stock".

This situation usually occurs when:

A customer returns to their abandoned cart and an item in their cart has sold out.
A customer is shopping for a popular product and adds it to their cart, but then the item goes out of stock while the customer is still shopping or decides to check out

Is there a way to have WooCommerce automatically add an "out of stock" text on the product lists in cart.

2

Answers


  1. Check this blog
    This will show a message like "99 in stock" or "out of stock" if item is sold out

     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 );
     }
    
    Login or Signup to reply.
  2. add_filter('woocommerce_cart_item_name', 'woocommerce_cart_item_show_outofstock', 10, 3);
    
    function woocommerce_cart_item_show_outofstock($item_name, $cart_item, $cart_item_key) {
    
        if ('outofstock' === $cart_item['data']->get_stock_status()) {
    
            $item_name .= "&nbsp;&nbsp;&nbsp;<i style='color:#e2401c;'>" . __('Out of stock', 'woocommerce') . "</i>";
        }
    
        return $item_name;
    }
    

    Add this to your active theme functions.php file.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search