I have a "Wholesaler" user. I am looking for a way to hide products with a given attribute "nonwh".
Asked
Active
Viewed 127 times
1 Answers
1
You didn't provide any code, but you could probably user something with the wp_get_current_user()
function. and the wc_get_product()
function.
$user = wp_get_current_user();
if ( in_array( 'Wholesaler', (array) $user->roles ) ) {
// This checks too see if the user has the role of Wholesaler.
}
And maybe wrap the above around the wc_get_product()
function.
$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
}
This is a function found in an answer here: How to check if product has a specific product attribute in Woocommerce
This should be a good start to what you are trying to accomplish.

JCBiggar
- 2,477
- 3
- 20
- 33