【问题标题】:Changing in WooCommerce email notification Order Item table "Product" label更改 WooCommerce 电子邮件通知订单项目表“产品”标签
【发布时间】:2017-09-20 05:08:42
【问题描述】:

我需要在 WooCommerce 订单项表电子邮件通知中将文本 (标签)“产品”更改为“票证”。

我该怎么做?
有可能吗?

谢谢

【问题讨论】:

  • 刚刚做到了! :) 有用! :) 谢谢!!!

标签: php wordpress woocommerce product email-notifications


【解决方案1】:

首先,我们需要获取电子邮件 ID 来定位所有电子邮件通知。唯一的方法是先获取它,然后在全局变量中设置值。

然后在 Wordpress gettext 动作挂钩中挂钩的自定义函数中,我们可以更改(翻译)所有电子邮件通知中的“产品”。

代码如下:

 ## Tested on WooCommerce 2.6.x and 3.0+

// Setting the email_is as a global variable
add_action('woocommerce_email_before_order_table', 'the_email_id_as_a_global', 1, 4);
function the_email_id_as_a_global($order, $sent_to_admin, $plain_text, $email){
    $GLOBALS['email_id_str'] = $email->id;
}


add_filter('gettext', 'wc_renaming_email_label', 50, 3);
function wc_renaming_email_label( $translated_text, $untranslated_text, $domain ) {

    // Getting the email ID global variable
    $refNameGlobalsVar = $GLOBALS;
    $email_id = $refNameGlobalsVar['email_id_str'];

    if( !is_admin() && $email_id ) {
        if( $untranslated_text == 'Product' )
            $translated_text = __( 'Ticket', $domain );
    }
    return $translated_text;
}

此代码位于您的活动子主题(或主题)的 function.php 文件中或任何插件文件中。

此代码在 WooCommerce 上从 2.6.x 到 3.0+ 进行了测试,并且可以正常工作。

【讨论】:

    【解决方案2】:

    如果您不想修改 WooCommerce 文件,请使用此插件https://wordpress.org/plugins/woo-custom-emails/

    如果您想从 WooCommerce 文件中编辑它,请修改 /wp-content/plugins/woocommerce/templates/emails/ 中的电子邮件模板

    【讨论】:

    • 似乎没有在电子邮件模板中编辑标签的选项
    • 请解释一下哪一个是Label?
    猜你喜欢
    • 2021-04-21
    • 2018-06-04
    • 2020-12-12
    • 1970-01-01
    • 2022-01-03
    • 2019-01-12
    • 2019-08-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多