1
votes

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

2 Answers

2
votes
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 );
    }
}
0
votes

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.