If statement – If user is logged in AND user role is wholesaler. Woocommerce
-
Hi there,
I hope somebody can help me.
I am trying to create two if statements to work together. ” If user is logged in AND their user role is wholesale then execute nothing. Else remove certain category from shop page.
I have got it to work with each if statement individually but need them to work together.
I haven’t very experience with using if statements etc so would appreciate anybody pointing out where I’m going wrong.
Many thanks!
Ralph
add_action( 'pre_get_posts', 'custom_pre_get_posts_query' ); function custom_pre_get_posts_query( $q ) { get_currentuserinfo(); global $current_user; if (is_user_logged_in() ) { if ( $current_user->ID) { $user_roles = $current_user->roles; $user_role = array_shift($user_roles); if ($user_role == 'wholesale') { } else { if ( ! $q->is_main_query() ) return; if ( ! $q->is_post_type_archive() ) return; if ( ! is_admin() ) { $q->set( 'tax_query', array(array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'trade' ), // Don't display products in the trade category on the shop page . For multiple category , separate it with comma. 'operator' => 'NOT IN' ))); } remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' ); } } } }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘If statement – If user is logged in AND user role is wholesaler. Woocommerce’ is closed to new replies.