【发布时间】:2021-05-28 07:46:35
【问题描述】:
我有一个“批发商”用户。我正在寻找一种方法来隐藏具有给定属性“nonwh”的产品。
【问题讨论】:
标签: php wordpress woocommerce
我有一个“批发商”用户。我正在寻找一种方法来隐藏具有给定属性“nonwh”的产品。
【问题讨论】:
标签: php wordpress woocommerce
您没有提供任何代码,但您可能可以使用 wp_get_current_user() 函数来使用某些东西。和wc_get_product() 函数。
$user = wp_get_current_user();
if ( in_array( 'Wholesaler', (array) $user->roles ) ) {
// This checks too see if the user has the role of Wholesaler.
}
也许将上面的内容包裹在 wc_get_product() 函数周围。
$products = wc_get_product( $product_id );
$nonwh = $product->get_attribute('nonwh');
if( ! empty( $nonwh ) ){
// Do nothing if product has the nonwh attribute
} else {
//Show Products
}
这是在此处的答案中找到的功能: How to check if product has a specific product attribute in Woocommerce
这应该是您想要完成的工作的良好开端。
【讨论】: