I need to run some functions/filters for specific user roles. This code filters the admin order page (Woocommerce) to only show orders that are in GBP.
add_filter('request', function($vars) {
global $typenow, $wpdb;
// Add logic to determine if the orders list should be filtered, and which
// currency
$currency = 'GBP';
if($typenow == 'shop_order') {
$vars['meta_query']['relation'] = 'AND';
// Only show orders in the specific currency
$vars['meta_query'] = array(
array(
'key' => '_order_currency',
'value' => $currency,
'compare' => '=',
),
);
}
return $vars;
}, 15 );
This works as expected.
What I need to do is make this code only run for certain roles.
The role I need to fire it on is uk_staff
.
I then need to create the same thing except for $currency = 'AUD';
and the role au_staff
.
Can anyone give me some help making this function only fire for certain roles?
if ( ! current_user_can( 'manage_options' ) ) return;
.global
statement, to that if the user have not (!
) the role, exit/return of the request.