特定WooCommerce产品类别的隐藏属性下拉列表
问题描述:
我的要求是在产品的归档页面/循环中隐藏特定类别的属性下拉列表,因为我从产品仪表板设置了默认的自定义属性可见性。 在我的小代码到目前为止它的工作,但它也隐藏在所有类别。 需要帮助。特定WooCommerce产品类别的隐藏属性下拉列表
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对象,你得到这样(Woocommerce兼容版本)中的ID:
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';
}
这应该工作这段时间。
即使这没有奏效。是否有可能有条件地触发行动挂钩? – SandeepTete