[英]Add shipping state to subject in WooCommerce new order email notification
I've already succeded finding a way to change the subject of the WooCommerce new order email notification.我已经成功地找到了一种方法来更改 WooCommerce 新订单 email 通知的主题。 The problem I'm facing, is that the object
$order
doesn't processes the shipping_state
of the user profile.我面临的问题是 object
$order
不处理用户配置文件的shipping_state
。
Here is the code:这是代码:
add_filter('woocommerce_email_subject_new_order', 'change_admin_email_subject', 1, 2);
function change_admin_email_subject( $subject, $order ) {
global $woocommerce;
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$subject = sprintf( 'Commande pour %s', $order->shipping_state);
return $subject;
}
I tried calling it directly from the user meta data, but it doesn't work, where it should appear the data, it appears blank.我尝试直接从用户元数据中调用它,但它不起作用,它应该出现数据的地方,它显示为空白。
Here is the code I tried:这是我尝试过的代码:
function change_admin_email_subject( $subject, $user) {
global $woocommerce;
$user = wp_get_current_user(); $current_user_id =
$user -> ID;
$user_billing_state = get_user_meta($current_user_id, 'shipping_state', true);
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$subject = sprintf( 'Commande pour %s',
$user_billing_state);
return $subject;
}
Any advice would be appreciated.任何意见,将不胜感激。
Your code attempt(s) contain some mistakes:您的代码尝试包含一些错误:
$order->shipping_state
is no longer applicable since WooCommerce 3 and has been replaced by $order->get_shipping_state()
$order->shipping_state
自 WooCommerce 3 起不再适用,已被$order->get_shipping_state()
取代global $woocommerce;
global $woocommerce;
is not necessary$blogname
, but you don't do anything with this data, for example you don't display it in the subject$blogname
,但您不对这些数据做任何事情,例如您没有在主题中显示它So you get:所以你得到:
function filter_woocommerce_email_subject_new_order( $subject, $order ) {
// Get shipping state
$shipping_state = $order->get_shipping_state();
// NOT empty
if ( ! empty( $shipping_state ) ) {
// Get blogname
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
// Change subject
$subject = sprintf( __( '%s: Commande pour %s', 'woocommerce' ), $blogname, $shipping_state );
}
return $subject;
}
add_filter( 'woocommerce_email_subject_new_order', 'filter_woocommerce_email_subject_new_order', 10, 2 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.