Reputation: 315
My requirement here is to hide attribute dropdown for a specific category in the archive page/loop of products as i have set default custom attribute visibility from product dashboard. In my small code so far it works, but it hides in all the categories as well. Need help.
add_filter('woocommerce_dropdown_variation_attribute_options_html','attrrj');
function attrrj(){
global $product;
//if(is_page(1881)){
if ( has_term( 'cup','product_cat', $product->ID ) ) {
return 'ok';
}
//}
}
Upvotes: 1
Views: 695
Reputation: 254493
With $product
WC_Product object you get the ID like this (Woocommerce compatibility versions):
global $product;
// get the product ID (Woocommerce compatibility versions)
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
if ( has_term( 'cup','product_cat', $product_id ) ) {
return 'ok';
}
This should work this time.
Upvotes: 1