Facebook Pixel

How to add custom text in WooCommerce confirmation email.


How to add custom text in WooCommerce confirmation email.

We had the privilege of working on a client’s project who wanted to add additional elements to the confirmation email. Indeed, having contracted us to create a site under WooCommerce, it was a question of customizing according to their needs. In this article, I explain how to add additional text or elements to a WooCommerce confirmation email.

Background and why to add or customize WooCommerce confirmation message

When you subscribe to WooCommerce or use the extension to create your website, you have standard features. In some cases, you may want to add new texts or additional links. In the case of our client, he wanted to send a link for making an appointment once the customer had completed the order. Below are some options available to you.

1- Overwrite the email template available in the WooCommerce plugin

If you go to the WooCommerce tab ⇒ Settings ⇒ Emails, and click on the manage button of the new order line, you will see an indication. Indeed, the indication explains how to create your own confirmation template.

To overwrite and modify this email template, copy woocommerce/templates/emails/admin-new-order.php to your theme’s folder: phoenix/woocommerce/emails/admin-new-order.php

In other words, if in your current theme, you create the folder woocommerce/emails/admin-new-order.php, you will create a template that meets your expectations.

The only problem with this approach is that the template remains static. Indeed, if your intention is to add custom text per product, this is not ideal. In addition, you must make sure to maintain this file or make constant updates.

2- Add dynamic content.

Supposing a scenario where you want to customize the text based on the product or product category. In this case, overwriting the basic templates is not enough. Now let’s see how to dynamically add the message you want to send. Below is a code snippet that you can use:

 


<?php 
add_action( 'woocommerce_email_order_meta', 'add_custom_message_to_email', 20, 3 );
function add_custom_message_to_email( $order, $sent_to_admin, $plain_text ) {
    foreach ( $order->get_items() as $item_id => $item ) {
        $product_id = $item->get_product_id();
        $lien_pour_le_rendez_vous = get_field( 'lien_pour_le_rendez_vous', $product_id );
        
        if ( !empty( $lien_pour_le_rendez_vous ) ) {
            echo '<p>Merci de nous avoir choisi pour Vous pouvez nous contacter en utilisant ce lien : <br>';
            echo '<a href="https://www.prositeweb.ca/contactez-nous/">https://www.prositeweb.ca/contactez-nous/</a></p>';
            break; // No need to check other products if we find one with the field
        }
    }
}

 

Using the above code, you will be able to add additional text in the WooCommerce confirmation email.

Other Approaches to Change WooCommerce Confirmation Email

There are other approaches to modify WooCommerce confirmation emails: using extensions. Below are the extensions you can use:

Conclusion

In conclusion to customize WooCommerce confirmation email you can use basic template, php code or modules or extensions.

Leave a comments:

We use cookies to ensure that we give you the best experience on our website. By continuing to use this site, you consent to our use of cookies. ... Our policy