Send email notification to Shop Owner, if a product was checked-out on a different site
When using Single Site Check-out type, the Global Cart is being processed at a specified shop in the network or one at the customer preference. All Products will be included in a single order created on the site where the check-out occurs.
On shop Networks, where the owner chose to use Shop Managers to allow individual sites to be run by individual users, when a new Order is created on the Check-out Shop, a notification e-mail might be required to be sent to the shop where the product originated. A custom code can be used to achieve this functionality.
The following code should be placed in a file e.g. woo-gc-custom.php inside you /wp-content/mu-plugins folder. If the folder does not exist on your WordPress, you should create it manually.
add_action( 'woocommerce_checkout_update_order_meta', 'woogc_woocommerce_checkout_update_order_meta' );
function woogc_woocommerce_checkout_update_order_meta ( $order_id )
{
$subject = 'New Order';
$order = wc_get_order( $order_id );
foreach( $order->get_items() as $key => $order_item )
{
switch_to_blog( $order_item->get_meta('blog_id') );
$product_name = $order_item->get_name();
$product_id = $order_item->get_product_id();
$product_variation_id = $order_item->get_variation_id();
$message = "A new order has received which include a product from your shop: \n" . $product_name . " " . get_permalink($product_id);
$to = get_option('admin_email');
wp_mail( $to, $subject, $message );
restore_current_blog();
}
}