Hello,
How to disable Add to Cart button in a product category? ex: Free Gift (slug: free-gift)
I have tried with this code, but not success. Please help.
add_action('init','remove_add_to_cart_button');
function remove_add_to_cart_button() {
if ( has_term( 'free-gift', 'product_cat' ) ) {
remove_action( 'woocommerce_after_shop_loop_item', 'avia_add_cart_button', 16);
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
}
Regards
Hey ciptanegara!
Thank you for using our theme.
Probably the init hook is to early for the has_term function.
Try the following:
add_action('init','remove_add_to_cart_button', 1000);
function remove_add_to_cart_button() {
remove_action( 'woocommerce_after_shop_loop_item', 'avia_add_cart_button', 16);
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
add_action( 'woocommerce_after_shop_loop_item', 'my_add_to_cart_button', 16 );
add_action( 'woocommerce_single_product_summary', 'my_add_to_cart_button_single', 30 );
function my_add_to_cart_button() {
if ( ! has_term( 'free-gift', 'product_cat' ) ) {
avia_add_cart_button();
}
}
function my_add_to_cart_button_single() {
if ( ! has_term( 'free-gift', 'product_cat' ) ) {
woocommerce_template_single_add_to_cart();
}
}
Best regards,
Günter
Perfect Günter! It worked. Thanks.
Best regards,
me