Php 为电子商务电子邮件通知主题创建其他变量/占位符

Php 为电子商务电子邮件通知主题创建其他变量/占位符,php,wordpress,woocommerce,placeholder,email-notifications,Php,Wordpress,Woocommerce,Placeholder,Email Notifications,从自定义订单状态激活新电子邮件通知时,我有以下主题占位符选项: “您可以使用以下占位符:{订单日期}、{订单编号}、{订单状态}、{账单名}、{账单姓}、{账单公司}、{博客名}、{网站标题}” 有没有办法为其他字段创建新的占位符? 基本上,我已经创建了一个名为test_pw的新隐藏字段,我希望能够将{billing_email}和{test_pw}添加到我的自定义电子邮件中 我已经尝试过这个代码,但我不知道如何格式化它 // Only for woocommerce versions 3.2

从自定义订单状态激活新电子邮件通知时,我有以下主题占位符选项:

“您可以使用以下占位符:{订单日期}、{订单编号}、{订单状态}、{账单名}、{账单姓}、{账单公司}、{博客名}、{网站标题}”

有没有办法为其他字段创建新的占位符? 基本上,我已经创建了一个名为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 );
}
//仅适用于woocommerce版本3.2+(最多3.2版)
添加过滤器('woocommerce\u email\u format\u string','filter\u email\u format\u string',20,2);
函数过滤器\电子邮件\格式\字符串($string,$email){
//获取WC_Order对象的实例
$order=$email->object;
//查找/关系对数组中需要的其他占位符
$additional_占位符=数组(
“{custom_one}”=>“‘我的替代品’,‘woocommerce’”,
“{shipping_city}”=>$order->get_shipping_city(),

“{yudu_pw}”=>$order->get_meta('yudu_pw'),//我正在尝试,但无法完全理解。我想包括客户的电子邮件地址和我创建的隐藏字段,我称之为test_pw。”{billing_email}=>$order->get_billing u email(),“{test test_pw}”=>$order->get_test pw(),非常感谢,但我还不知道在其余部分中插入代码的位置和方式。感谢您的尝试,但您可能假设我是一名编程人员。lolI修改了问题,它不适用于页脚文本。若要向页脚文本添加自定义占位符,请扩展woocommerce\u电子邮件\u页脚\u文本过滤器。它仍然有效;)。