为 Woocommerce 电子邮件通知主题创建额外的 variables/placeholders
Create additional variables/placeholders for Woocommerce email notifications subject
从自定义订单状态激活新电子邮件通知时,我有以下主题占位符选项:
"You can use the following placeholders: {order_date}, {order_number}, {order_status}, {billing_first_name}, {billing_last_name}, {billing_company}, {blogname}, {site_title}"
有没有办法为其他字段创建新的占位符?
基本上,我创建了一个名为 test_pw 的新隐藏字段,我希望能够将 {billing_email} 和 {test_pw} 添加到我的自定义电子邮件中。
我已经尝试使用您建议的这段代码,但我不确定如何格式化它。
// Only for woocommerce versions 3.2 + (up to 3.2)
add_filter( 'woocommerce_email_format_string' , 'filter_email_format_string', 20, 2 );
function filter_email_format_string( $string, $email ) {
// Get the instance of the WC_Order object
$order = $email->object;
// Additional wanted placeholders in the array of find / relace pairs
$additional_placeholders = array(
'{custom_one}' => __('my replacement one','woocommerce'),
'{billing_email}' => $order->get_billing_email(),
'{test_pw}' => $order->get_test_pw(),
);
// return the clean string with new replacements
return str_replace( array_keys( $additional_placeholders ), array_values( $additional_placeholders ), $string );
}
这是一个示例,将向您展示如何为电子邮件通知添加新的占位符主题:
// Only for woocommerce versions 3.2 + (up to 3.2)
add_filter( 'woocommerce_email_format_string' , 'filter_email_format_string', 20, 2 );
function filter_email_format_string( $string, $email ) {
// Get the instance of the WC_Order object
$order = $email->object;
// Additional wanted placeholders in the array of find / relace pairs
$additional_placeholders = array(
'{custom_one}' => __('my replacement one','woocommerce'),
'{shipping_city}' => $order->get_shipping_city(),
'{yudu_pw}' => $order->get_meta( 'yudu_pw' ), // <=== HERE
);
// return the clean string with new replacements
return str_replace( array_keys( $additional_placeholders ), array_values( $additional_placeholders ), $string );
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。 已测试并有效 仅适用于 Woocommerce 3.2 及更高版本…
从自定义订单状态激活新电子邮件通知时,我有以下主题占位符选项:
"You can use the following placeholders: {order_date}, {order_number}, {order_status}, {billing_first_name}, {billing_last_name}, {billing_company}, {blogname}, {site_title}"
有没有办法为其他字段创建新的占位符? 基本上,我创建了一个名为 test_pw 的新隐藏字段,我希望能够将 {billing_email} 和 {test_pw} 添加到我的自定义电子邮件中。
我已经尝试使用您建议的这段代码,但我不确定如何格式化它。
// Only for woocommerce versions 3.2 + (up to 3.2)
add_filter( 'woocommerce_email_format_string' , 'filter_email_format_string', 20, 2 );
function filter_email_format_string( $string, $email ) {
// Get the instance of the WC_Order object
$order = $email->object;
// Additional wanted placeholders in the array of find / relace pairs
$additional_placeholders = array(
'{custom_one}' => __('my replacement one','woocommerce'),
'{billing_email}' => $order->get_billing_email(),
'{test_pw}' => $order->get_test_pw(),
);
// return the clean string with new replacements
return str_replace( array_keys( $additional_placeholders ), array_values( $additional_placeholders ), $string );
}
这是一个示例,将向您展示如何为电子邮件通知添加新的占位符主题:
// Only for woocommerce versions 3.2 + (up to 3.2)
add_filter( 'woocommerce_email_format_string' , 'filter_email_format_string', 20, 2 );
function filter_email_format_string( $string, $email ) {
// Get the instance of the WC_Order object
$order = $email->object;
// Additional wanted placeholders in the array of find / relace pairs
$additional_placeholders = array(
'{custom_one}' => __('my replacement one','woocommerce'),
'{shipping_city}' => $order->get_shipping_city(),
'{yudu_pw}' => $order->get_meta( 'yudu_pw' ), // <=== HERE
);
// return the clean string with new replacements
return str_replace( array_keys( $additional_placeholders ), array_values( $additional_placeholders ), $string );
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。 已测试并有效 仅适用于 Woocommerce 3.2 及更高版本…