在WooCommerce电子邮件通知订单表中更改产品标签 [英] Changing in WooCommerce email notification Order Item table "Product" label

查看:18
本文介绍了在WooCommerce电子邮件通知订单表中更改产品标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我将如何执行此操作?
有可能吗?

谢谢

推荐答案

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

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

代码如下:

 ## 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;
}

此代码放在活动子主题(或主题)的函数.php文件或任何插件文件中。

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

这篇关于在WooCommerce电子邮件通知订单表中更改产品标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆