I'm building a plugin where a customer(s) is attached to a shop manager. The shop manager can only see orders of customers that are attached to him. The plugin has two parts :
The first one, i already built it, hide all orders that aren't attached to a shop manager. Here's the code in case you want to see how it works :
function before_checkout_create_order($order, $data) {
$store_manager_id = '';
switch ($order->get_user_id()) {
case 34:
$store_manager_id = 18;
break;
case 33:
$store_manager_id = 20;
break;
}
$order->update_meta_data('_store_manager_id', $store_manager_id);
}
add_action('woocommerce_checkout_create_order', 'before_checkout_create_order', 20, 2);
function custom_admin_shop_manager_orders($query) {
global $pagenow;
$qv = &$query->query_vars;
$currentUserRoles = wp_get_current_user()->roles;
$user_id = get_current_user_id();
if (in_array('shop_manager', $currentUserRoles)) {
if ( $pagenow == 'edit.php' &&
isset($qv['post_type']) && $qv['post_type'] == 'shop_order' ) {
// I use the meta key from step 1 as a second parameter here
$query->set('meta_key', '_store_manager_id');
// The value we want to find is the $user_id defined above
$query->set('meta_value', $user_id);
}
}
return $query;
}
add_filter('pre_get_posts', 'custom_admin_shop_manager_orders');
?>
The second part where i need help : I'm trying to have emails only for the shop manager concerned.
Eg : A customer order some products, the shop manager attached to him receives an email about his order but all others shop managers dont receive anything.
If you have any ideas feel free !