marketpress - customizing notifications to buyers

In MarketPress 2.9, I was able to customize our notifications to buyers with unique information about the product purchased by adding a function to pull the product post excerpt into the notifications. Each excerpt includes unique information that differs per product. Is there any way to edit the notifications in 3.0 and above? It looks like the notifications are now access protected in the class-mp-order file?

My old way of doing this in 2.9 was adding the code below to marketpress.php:

function add_items_in_email( $msg, $order ) {
	$items_html = '';
	foreach ( $order->mp_cart_info as $key => $item ) {
		$inside = array_shift( $item );
		$items_html .= "Class Information: " . get_post_field( 'post_excerpt', $key );
	}

Thanks for your help!

  • Ivan

    Hi AFS_Dev !

    It seems you provided not a full part of your code.
    Anyway, you can use mp_order/notification_body filter for notifications of new order and mp_order/shipment_notification for notifications that the order has shipped. Both of them use two attributes: $msg - content of message and $order - object of order. Also, for get cart info - you should use this code: $mp_cart_info = $order->get_meta( 'mp_cart_info' );
    In general cases it looks like this:

    <?php
    function wpmu_marketpress_customizing_notifications_to_buyers( $msg,  $order ) {
    	$mp_cart_info = $order->get_meta( 'mp_cart_info' );
    	foreach ( $mp_cart_info as $key => $item ) {
    		//here code for changing or adding some information to $msg
    	}
    
    	return $msg;
    }
    
    add_filter( 'mp_order/notification_body', 'wpmu_marketpress_customizing_notifications_to_buyers', 10, 2 );

    Best regards,
    Ivan.

  • AFS_Dev

    Thanks so much for your help. You're right--I didn't paste the entire code. It was:

    function add_items_in_email( $msg, $order ) {
    	$items_html = '';
    	foreach ( $order->mp_cart_info as $key => $item ) {
    		$inside = array_shift( $item );
    		$items_html .= "Class Information: " . get_post_field( 'post_excerpt', $key );
    	}
    	$msg = str_replace( 'ORDERITEMS', $items_html, $msg );
    	return $msg;
    }

    I appreciate the code you posted, but I'm not quite sure how to use it. I tried merging my code into yours like below, but that broke the site when I added it to class-mp-order.

    <?php
    function wpmu_marketpress_customizing_notifications_to_buyers( $msg,  $order ) {
    	$mp_cart_info = $order->get_meta( 'mp_cart_info' );
    	foreach ( $mp_cart_info as $key => $item ) {
    		$inside = array_shift( $item );
    		$items_html .= "Class Information: " . get_post_field( 'post_excerpt', $key );
    	}
    	$msg = str_replace( 'ORDERITEMS', $items_html, $msg );
    	return $msg;
    }
    
    add_filter( 'mp_order/notification_body', 'wpmu_marketpress_customizing_notifications_to_buyers', 10, 2 );

    I just need the extra info on the initial order notification email to buyers.

  • Adam Czajczyk

    Hello AFS_Dev!

    Could you try moving that code (the one that you created/merged) from the "class-mp-order" file to the MU plugin? To do this, first remove it from the class file and then:

    - create an empty file with a ".php" extension (e.g. "mp-custom-notifications.php")
    - put that code inside using some "clean text" editor (e.g. Notepad++, Sublime or similar)
    - using FTP (or cPanel's "File Manager" tool) upload the file to the "/wp-content/mu-plugins" folder

    If there's no "mu-plugins" folder right inside the "wp-content" folder, just create it.

    Let us know if that helped, please!

    Best regards,
    Adam

  • AFS_Dev

    Thanks so much for the guidance on the MU plugin. I really seem to be getting closer now!

    The one piece that I am still missing is getting the product excerpt text to show up in the email. The "Class Information:" title written into the function shows up, but not the excerpt. The get_post_field( 'post_excerpt', $key ) directive does not seem to work for us like it did in the older version of MP.

    Any ideas of a different way to pull that info into the notification emails?

    Thank you--I cannot tell you how much I appreciate the help.

  • Ivan

    Hi AFS_Dev !

    Please, try this code

    <?php
    
    function wpmu_marketpress_customizing_notifications_to_buyers( $msg,  $order ) {
    	$items_html = '';
    	$mp_cart_info = $order->get_meta( 'mp_cart_items' );
    	foreach ( $mp_cart_info as $key => $item ) {
    		$items_html .= "Class Information: " . get_post_field( 'post_excerpt', $key );
    	}
    	$msg = str_replace( 'ORDERITEMS', $items_html, $msg );
    	return $msg;
    }
    
    add_filter( 'mp_order/notification_body', 'wpmu_marketpress_customizing_notifications_to_buyers', 10, 2 );

    I tested it for my local installation and it works.

    Note: you should be sure that bought products have Excerpt field
    and also you should be sure that you inserted ORDERITEMS to text of Customer Notification

    Best regards,
    Ivan.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.