Tutorials for web designers and developers
Tutorials for Developers_
Search
Close this search box.

How to hide Add to cart button for specific variations WooCommerce?

hide-add-to-cart-button-for-specific-variation-woocommerce-product

To hide the variation of woocommerce variable product, I first changed the status of variation to “On backorder” and saved the product.

Secondly, I added the following code to hide the add to cart button when product variation with “on backorder” status is selected.

jQuery(function($){
$("form.variations_form.cart").on('DOMSubtreeModified', function(){
if($(".single-product p.stock.available-on-backorder").length){
        $("button.single_add_to_cart_button.button").hide();
        console.log('added');
    }
    else {
        $("button.single_add_to_cart_button.button").show();
        console.log('removed'); 
    }
});
    
});

Final Result

Leave a Reply

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