Skip Navigation

[Resolved] Woocommerce email placeholders from custom fields

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 16 replies, has 2 voices.

Last updated by Minesh 10 months, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2677837

Hi Minesh

Now you should be able to log in.

There is no problem URL because I did not come so far.

The problem was that when I pasted the code above into the function.php file the whole site got into critical error mode. When I removed the code from the function.php file the site was up and running again.

My guess is that it’s something wrong with code.

BR
Tobias

#2677853

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added the code I shared to "Custom Code" section offered by Toolset:
=> hidden link

function func_add_custom_email_placeholders( $string, $email ) {
// Get WC_Order object from email
$order = $email->object;
 
/// Get and Loop Over Order Items
foreach ( $order->get_items() as $item_id => $item ) {
$product_id = $item->get_product_id();
 
$for_och_efternamn_name = get_post_meta($product_id, 'wpcf-for-och-efternamn', true);
$e_post_uppdragsgivare_name = get_post_meta($product_id, 'wpcf-e-post-uppdragsgivare', true);
$telefonnummer_uppdragsgivare_name = get_post_meta($product_id, 'wpcf-telefonnummer-uppdragsgivare', true);
 
}
 
// Add new placeholders
$new_placeholders = array(
'{_for_och_efternamn_name}' => $for_och_efternamn_name,
'{_e_post_uppdragsgivare_name}' => $e_post_uppdragsgivare_name,
'{_telefonnummer_uppdragsgivare_name}' => $telefonnummer_uppdragsgivare_name,
 
);
// return the string with new placeholder replacements
return str_replace( array_keys( $new_placeholders ), array_values( $new_placeholders ), $string );
}
add_filter( 'woocommerce_email_format_string' , 'func_add_custom_email_placeholders', 20, 2 );

More info:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#benefits-of-adding-custom-code-using-toolset

#2678268

Hi Minesh

Thank you very much!

It works when I use the Woocommerce default customizer. When I try to add the placeholders in a template from a “email customizer plugin” it doesn’t work. Is this something you can help with or should I contact the plugin support?

BR
Tobias