skip to Main Content

Im trying to hide the add to cart button in woocommerce for all products except a varibale product i have. I have tried the following which leaves the variable select options (which is what i want) but it hides the add to cart button (which i don’t want).

add_filter( 'woocommerce_is_purchasable', '__return_false' ); 

add_action( 'woocommerce_single_product_summary', 'hide_add_to_cart_button_variable_product', 1, 0 );
function hide_add_to_cart_button_variable_product() { 

remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20);
}

Is there a way to do this?

All my products are simple products except for this single variable products, so maybe there is a function to hide the cart button for all simples except variables?

2

Answers


  1. I think you can just edit the simple.php template file in the add-to-cart directory so it wouldn’t show the button for simple products.

    Login or Signup to reply.
  2. add_action('woocommerce_single_product_summary', 'wp66176371_remove_product_description_add_cart_button', 1 );
    function wp66176371_remove_product_description_add_cart_button() {
        global $product;
        if ( !empty($product) && $product->is_type( 'simple' ) ) {
            remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search