When activating new email notifications from Custom order statuses I have this options for Subject placeholders:
"You can use the following placeholders: {order_date}, {order_number}, {order_status}, {billing_first_name}, {billing_last_name}, {billing_company}, {blogname}, {site_title}"
Is there a way of creating new placeholders for other fields?
Basically, I have created a new hidden field called test_pw and I want to be able to add {billing_email} and {test_pw} to my custom emails.
I have tried with this code kindly suggested but I am not sure how to format it.
// 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 );
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…