Changing the new order email
-
I’m trying to change the new order email that is sent to admins but I just can’t seem to get it to work.
I found some code elsewhere that suggested I could remove the action for order_status_pending_to_processing, duplicate the official function and add a new action for it:
remove_action('order_status_pending_to_processing', 'jigoshop_new_order_notification'); add_action( 'order_status_pending_to_processing', 'add_coupon_code_email' ); function add_coupon_code_email( $order_id ) { $jigoshop_options = Jigoshop_Base::get_options(); $order = new jigoshop_order($order_id); $subject = html_entity_decode(sprintf(__('[%s] New Customer Order (%s)', 'jigoshop'), get_bloginfo('name'), $order->get_order_number()), ENT_QUOTES, 'UTF-8'); ob_start(); echo __("You have received an order from ", 'jigoshop') . $order->billing_first_name . ' ' . $order->billing_last_name . __(". Their order is as follows:", 'jigoshop') . PHP_EOL . PHP_EOL; add_header_info($order); add_order_totals($order, false, true); add_customer_details($order); add_billing_address_details($order); add_shipping_address_details($order); $message = ob_get_clean(); //- $discounts = @$order->order_discount_coupons; $codes = ""; if($discounts){ foreach($discounts as $discount){ $codes .= @$discount->code . ", "; } } $message .= PHP_EOL."Discount Code Used: $codes". PHP_EOL; //- $message = apply_filters('jigoshop_change_new_order_email_contents', $message, $order); $message = html_entity_decode(strip_tags($message), ENT_QUOTES, 'UTF-8'); add_filter( 'wp_mail_from_name', 'jigoshop_mail_from_name', 99 ); wp_mail($jigoshop_options->get_option('jigoshop_email'), $subject, $message, "From: " . $jigoshop_options->get_option('jigoshop_email') . "\r\n"); remove_filter( 'wp_mail_from_name', 'jigoshop_mail_from_name', 99 ); // $msg=var_export($order,true); @wp_mail("address removed","Debug",$msg); }
This is mostly the same as the original except I’m trying to get the discount codes used for the order and also send a var_export of the $order to another email address.
Although admin is still getting the email, the discount code part isn’t included at all even if it’s just with no codes shown, and the second email isn’t being sent.
The error_log is saying the add_header_info() function doesn’t exist which seems strange to me as the original function had the call and mine is almost identical.
What have I done wrong?
- The topic ‘Changing the new order email’ is closed to new replies.