How to CC to network admin email in marketpress multisite setup?

Hi, the marketpress multisite network i setup is relatively a small one and I would like the network admin to receive email notifications on the orders. What I did was a custom hack to marketpress.php as below

function mail( $to, $subject, $msg ) {
...
//return wp_mail( $to, $subject, $msg, "Content-Type: text/html; charset=UTF-8" );
//replace above commented function to CC network admin below
switch_to_blog(1);
$network_admin_email = get_bloginfo( 'admin_email' );
restore_current_blog();
$headers[] = "Content-Type: text/html; charset=UTF-8";
$headers[] = 'Cc: '. $network_admin_email;
return wp_mail( $to, $subject, $msg, $headers );
}

as im well aware this hack can disappear on plugin update, just wondering if there is a better way to have this persist?

  • Marko Miljus

    There is an hook named mp_new_order (which triggers for new orders) and mp_order_paid which triggers on order create if the order is paid.

    So, you can do something like this (add this to your theme's functions.php for instance so you don't lose it after plugin update. You can also make a separate plugin for it if you want.):

    add_action( 'mp_new_order', 'new_mp_new_order_notification', 10, 1 );

    function new_mp_new_order_notification( $order ) {
    	global $mp;
    
    	if ( !$order )
    		return false;
    
    	$admin_email = 'youremailhere@example.com'; // ADD YOUR EMAIL HERE
    
    	$subject = apply_filters( 'mp_order_notification_subject', $mp->filter_email( $order, stripslashes( $mp->get_setting( 'email->new_order_subject' ) ) ), $order );
    	$msg	 = apply_filters( 'mp_order_notification_body', $mp->filter_email( $order, stripslashes( $mp->get_setting( 'email->new_order_txt' ) ) ), $order );
    	$msg	 = apply_filters( 'mp_order_notification_' . $_SESSION[ 'mp_payment_method' ], $msg, $order );
    
    	$mp->mail( $order->mp_shipping_info[ 'email' ], $subject, $msg );
    
    	//send message to admin
    	$subject = __( 'New Order Notification: ORDERID', 'mp' );
    	$msg	 = __( "A new order (ORDERID) was created in your store:
    
    Order Information:
    ORDERINFOSKU
    
    Shipping Information:
    SHIPPINGINFO
    
    Email: %s
    
    Payment Information:
    PAYMENTINFO
    
    You can manage this order here: %s", 'mp' );
    
    	$subject	 = $mp->filter_email( $order, $subject );
    	$subject	 = apply_filters( 'mp_order_notification_admin_subject', $subject, $order );
    	$msg		 = $mp->filter_email( $order, $msg, true );
    	$msg		 = sprintf( $msg, $order->mp_shipping_info[ 'email' ], admin_url( 'edit.php?post_type = product&page = marketpress-orders&order_id = ' ) . $order->ID );
    	$msg		 = apply_filters( 'mp_order_notification_admin_msg', $msg, $order );
    	$store_email = $admin_email;
    	$mp->mail( $store_email, $subject, $msg );
    }

    let me know does it work for you or if you need any further assistance.

    Cheers,
    Marko

  • Vinod Dalvi

    Hi @ic1980,

    Both the code snippet that you have shared worked for me displaying the network admin email set in the network settings as shown in the attached screenshot.

    Could you please try displaying the network admin email using the code snippets as following so that we can confirm whether the correct email id is fetching or there is any issue sending email to the network admin?

    switch_to_blog(1);
    $admin_email = get_site_option( 'admin_email' );
    restore_current_blog();
    echo $admin_email;

    and

    $admin_email = get_site_option( 'admin_email' );
    echo $admin_email;

    Regards,
    Vinod Dalvi

  • ic1980

    Ok.. must've hit my head or something as i thought the code will grab the email from super admin.. apologize for the silly mistake. Confirmed it now works when set network admin email with this code

    $admin_email = get_site_option( 'admin_email' ); //network admin email

    incidentally if the below code is used,

    switch_to_blog(1);
    $admin_email = get_bloginfo( 'admin_email' );
    restore_current_blog();

    it grabs the email from the blog's General Settings-> Email Address

    thanks for the awesome support

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.