, . 2 :
1) pre_get_posts , , . . , 'Wholesale' '123'.
:
function wholeseller_role_cat( $query ) {
$current_user = wp_get_current_user();
if ( $query->is_main_query() ) {
if ( in_array( 'wholeseller', $current_user->roles ) ) {
$query->set( 'cat', '123' );
} else {
$query->set( 'cat', '-123' );
}
}
}
add_action( 'pre_get_posts', 'wholeseller_role_cat' );
function.php .
2) woocommerce_product_query WooCommerce. ( , 'Wholesale' '123').
:
function wholeseller_role_cat( $q ) {
$current_user = wp_get_current_user();
if ( in_array( 'wholeseller', $current_user->roles ) ) {
$q->set( 'tax_query', array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => '123',
)
) );
} else {
$q->set( 'tax_query', array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => '123',
'operator' => 'NOT IN'
)
) );
}
}
add_action( 'woocommerce_product_query', 'wholeseller_role_cat' );
function.php .
slug , ( ):
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'wholesale',
, , woocommerce if statements, .
: