Reputation: 483
How can I disable the "add to basket" button for products only on the "categories" page?
I still want it visible on the product page.
Many thanks
Upvotes: 2
Views: 1973
Reputation: 254383
The following will disable add to cart button on product category archive pages:
// Disable add to cart on product category archive pages
add_filter( 'woocommerce_is_purchasable', 'disable_purchasable_on_product_category_archives', 10, 2 );
function disable_purchasable_on_product_category_archives( $purchasable, $product ) {
if( is_product_category() )
$purchasable = false;
return $purchasable;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
To target specific product archive pages you will replace use this instead:
add_filter( 'woocommerce_is_purchasable', 'disable_purchasable_on_product_category_archives', 10, 2 );
function disable_purchasable_on_product_category_archives( $purchasable, $product ) {
// HERE define your product category terms
$terms = array( 'shirts', 'games' );
if( is_product_category( $terms ) )
$purchasable = false;
return $purchasable;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
See: Woocommerce Conditional Tags
Upvotes: 4