Categories

Sunday, November 24, 2024
#919814419350 therichposts@gmail.com
WoocommerceWoocommerce HooksWordpress

How to Customize or Add Content to WooCommerce Order Emails?

How to Customize or Add Content to WooCommerce Order Emails

Hello guys how are you? Welcome back to my channel. Today in this post I am going to show you How to Customize or Add Content to WooCommerce Order Emails?

Guys I have used both latest versions WordPress 6.3 and WooCommerce 8.1.

Live Demo

Guys if you are new in WordPress or in WooCommerce then please check the below links for some good tutorials:

  1. WooCommerce Hooks
  2. WordPress Tricks
  3. WordPress Hooks
How to Customize or Add Content to WooCommerce Order Emails?
How to Customize or Add Content to WooCommerce Order Emails?

Guys here is the working code snippet and please use it carefully:

1. Guys here is the code snippet and you need to add your theme’s functions.php file:

add_action( 'woocommerce_email_before_order_table', 'trich_add_content_specific_email', 20, 4 );
  
function trich_add_content_specific_email( $order, $sent_to_admin, $plain_text, $email ) {
   if ( $email->id == 'customer_processing_order' ) {
      echo '<h2 class="email-upsell-title">Get 20% off</h2><p class="email-upsell-p">Thank you for making this purchase! Come back and use the code "<strong>Back4More</strong>" to receive a 20% discount on your next purchase! Click here to continue shopping.</p>';
   }
}

2. Using the same snippet above, you can call different types of emails by changing the email ID:

if ( $email->id == 'cancelled_order' ) {}
if ( $email->id == 'customer_completed_order' ) {}
if ( $email->id == 'customer_invoice' ) {}
if ( $email->id == 'customer_new_account' ) {}
if ( $email->id == 'customer_note' ) {}
if ( $email->id == 'customer_on_hold_order' ) {}
if ( $email->id == 'customer_refunded_order' ) {}
if ( $email->id == 'customer_reset_password' ) {}
if ( $email->id == 'failed_order' ) {}
if ( $email->id == 'new_order' ) {}

3. Here is the hook for new customer account email:

add_action( 'woocommerce_email_before_order_table', 'trich_add_content_specific_email', 20, 4 );
   
function trich_add_content_specific_email( $order, $sent_to_admin, $plain_text, $email ) {
   if ( $email->id == 'customer_new_account' ) {
      echo 'Add your content.';
   }
}

This is it guys and if you will have any kind of query, suggestion or requirement then feel free to comment below.

Jassa

Developer’s King

Thanks

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.