最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - How to override email text New Customer Order?

programmeradmin4浏览0评论

Im trying to override the admin email template text "New customer order" to "New order" in function.php, but i can not finde any info on google. Can somebody please give me a hint! :)

Im trying to override the admin email template text "New customer order" to "New order" in function.php, but i can not finde any info on google. Can somebody please give me a hint! :)

Share Improve this question asked Mar 31, 2016 at 13:14 TonyTony 11 silver badge1 bronze badge
Add a comment  | 

2 Answers 2

Reset to default 0

The easiest way to override the WooCommerce emails is to copy woocommerce/templates/emails/admin-new-order.php to yourtheme/woocommerce/emails/admin-new-order.php and make any changes in your version of the template. This will ensure that any changes you make do not get lost during any subsequent upgrades.

The text displayed in the subject line of the email is controlled via the GUI and may need changing if you wish to keep the 'New Order' text the same throughout.

However, if you really wanted to go down the route of changing the header text through the functions.php file, you could potentially hook into 'woocommerce_email_header':

function action_woocommerce_email_header( $email_heading ) { 
    // Change the email heading in here.
}; 
add_action( 'woocommerce_email_header', 'action_woocommerce_email_header', 10, 1 );

The $email_heading will be a string value containing the full HTML markup of the email header, it will contain the text 'New customer order' so you could do a simple str_replace, searching $email_heading for 'New customer order' and replacing it with 'New order'. For example:

function action_woocommerce_email_header( $email_heading ) { 
    $new_email_heading = str_replace( 'New customer order', 'New order', $email_heading );
    return $new_email_heading;
}; 
add_action( 'woocommerce_email_header', 'action_woocommerce_email_header', 10, 1 );

This is only a very crude example as you will need to cater for occurrences where 'New customer order' isn't present, for example. Hopefully it'll get you started along the right tracks.

You can use a filter for this:

/*
 * goes in theme functions.php or a custom plugin
 *
 *   woocommerce_email_heading_new_order
 *   woocommerce_email_heading_customer_processing_order
 *   woocommerce_email_heading_customer_completed_order
 *   woocommerce_email_heading_customer_invoice
 *   woocommerce_email_heading_customer_note
 *   woocommerce_email_heading_low_stock
 *   woocommerce_email_heading_no_stock
 *   woocommerce_email_heading_backorder
 *   woocommerce_email_heading_customer_new_account
 *   woocommerce_email_heading_customer_invoice_paid
 *
 * USAGE: add_filter('woocommerce_email_heading_new_order', 'my_filter_email_heading_new_order', 10, 2);
 *
 **/


function my_filter_email_heading_new_order($email_heading, $email){

    /* get info if needed */
    $order_id = $email->get_id();

    /* Translated version *
    $email_heading = sprintf( __('Order #%1$s', 'twenty-sixteen'), $order_id );

    /* simple version */
    $email_heading = 'Hello world';

    return $email_heading;
}
add_filter('woocommerce_email_heading_new_order', 'my_filter_email_heading_new_order', 10, 2);
发布评论

评论列表(0)

  1. 暂无评论