更改 WooCommerce 电子邮件通知订单项 table "Product" 标签
Changing in WooCommerce email notification Order Item table "Product" label
我需要将 WooCommerce 订单项 table 电子邮件通知中的文本 (标签) "Product" 更改为 "Ticket"。
我该怎么做?
可能吗?
谢谢
如果您不想修改 WooCommerce 文件,请使用此插件 https://wordpress.org/plugins/woo-custom-emails/
如果您想从 WooCommerce 文件中编辑它,请修改 /wp-content/plugins/woocommerce/templates/emails/
中的电子邮件模板
首先我们需要获取电子邮件 ID 以定位所有电子邮件通知。唯一的办法就是先获取,然后在全局变量中设置值。
然后在Wordpress gettext
action hook 中挂接的自定义函数中,我们可以在所有电子邮件通知中更改(翻译)"Product"。
代码如下:
## 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+ 上进行了测试并且有效。
我需要将 WooCommerce 订单项 table 电子邮件通知中的文本 (标签) "Product" 更改为 "Ticket"。
我该怎么做?
可能吗?
谢谢
如果您不想修改 WooCommerce 文件,请使用此插件 https://wordpress.org/plugins/woo-custom-emails/
如果您想从 WooCommerce 文件中编辑它,请修改 /wp-content/plugins/woocommerce/templates/emails/
中的电子邮件模板首先我们需要获取电子邮件 ID 以定位所有电子邮件通知。唯一的办法就是先获取,然后在全局变量中设置值。
然后在Wordpress gettext
action hook 中挂接的自定义函数中,我们可以在所有电子邮件通知中更改(翻译)"Product"。
代码如下:
## 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+ 上进行了测试并且有效。