隐藏特定 WooCommerce 产品类别的属性下拉列表
Hide attribute dropdown for a specific WooCommerce product category
我的要求是隐藏产品存档 page/loop 中特定类别的属性下拉列表,因为我已经从产品仪表板设置了默认的自定义属性可见性。
到目前为止,在我的小代码中它可以工作,但它也隐藏在所有类别中。
需要帮助。
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';
}
//}
}
使用 $product
WC_Product 对象你会得到这样的 ID(Woocommerce 兼容版本):
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';
}
这次应该可以了。
我的要求是隐藏产品存档 page/loop 中特定类别的属性下拉列表,因为我已经从产品仪表板设置了默认的自定义属性可见性。 到目前为止,在我的小代码中它可以工作,但它也隐藏在所有类别中。 需要帮助。
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';
}
//}
}
使用 $product
WC_Product 对象你会得到这样的 ID(Woocommerce 兼容版本):
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';
}
这次应该可以了。