How to Make

How to Disable "Out of Stock" Message on Cart Page in WooCommerce?

How to Disable "Out of Stock" Message on Cart Page in WooCommerce?

WooCommerce offers its users
is a very powerful tool as it gives you the possibility to make changes according to your requests. Often the WooCommerce cart will give an out of stock error message, even if you have changed the display format to "Never show out of stock" in the settings.

How to Disable "Out of Stock" Message on Cart Page in WooCommerce?

Follow the path below to solve this problem easily. You can solve this problem by adding a simple code to your website.
 Dashboard > Appearance > Theme Editor > Theme Functions

Then add the following code to the end of the existing code.

function remove_stock_info_error($error){
 
    global $woocommerce;
 
    foreach ($woocommerce->cart->cart_contents as $item) {
 
        $product_id = isset($item['variation_id']) ? $item['variation_id'] : $item['product_id'];
 
        $product = new WC_Product_Factory();
 
        $product = $product->get_product($product_id);
 
 
 
        if ($item['quantity'] > $product->get_stock_quantity()){
 
            $name = $product->get_name();
 
            $error = 'Sorry, there is not enough "'.$name.'" None. Please edit your cart and try again. We apologize for any inconvenience caused.';
 
            return $error;
 
        }
 
    }
 
}add_filter( 'woocommerce_add_error', 'remove_stock_info_error' );

After adding the code Update File Click, that's it.

Leave a Reply

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