简体   繁体   English

在 WooCommerce 新订单 email 通知中添加运输 state

[英]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()取代
  • The use of global $woocommerce; global $woocommerce; is not necessary没有必要
  • You use $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.

相关问题 WooCommerce 中新订单电子邮件通知的自定义主题 - Custom subject for New Order Email notification in WooCommerce Woocommerce将新订单通知发送到不同的电子邮件(基于运送国家) - Woocommerce new order notification to different email based on shipping country 基于 Woocommerce 新订单通知的配送方式 ID 的电子邮件收件人 - Email recipients based on Shipping method Id for Woocommerce new order notification 在 WooCommerce 的新订单电子邮件中的项目下添加运输类别? - Add shipping class under items in New Order email in WooCommerce? Woocommerce-将用户名添加到新订单电子邮件主题行 - Woocommerce - Add username to new order email subject line 如何将产品 SKU 添加到 WooCommerce 新订单电子邮件主题 - How to add product SKUs to WooCommerce new order email subject 根据送货方式 ID 在 WooCommerce 新订单电子邮件通知中隐藏送货地址 - Hide shipping address in WooCommerce new order email notification depending on shipping method id 将订单总重量添加到WooCommerce新订单电子邮件通知中 - Add the order total weight to WooCommerce new order email notification 在 WooCommerce 4+ 中添加发送电子邮件通知的新订单状态 - Add a new order status that Send an email notification in WooCommerce 4+ 将电子邮件收件人添加到 Woocommerce 中本地取货的新订单通知 - Add email recipients to New order notification for Local pickup in Woocommerce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM