Displaying Shortcodes in Email


I have a custom email template and I want to display a custom shortcode. It looks fine in the site and woocommerce email preview. I tried including it in a woocomerce email template. However, the script shows up. I’m using Customer new account email template and have removed most of the content in the body:

`<?php echo do_shortcode( ‘[short_code_sample]’ );?>`

In my functions.php, I have a function that creates the email. I do receive the email but the short code doesn’t render:


$mailer = WC()->mailer();

//format the email

$recipient = “[email protected]”;

$subject = “Upcoming Webinars!”;

$body = file\_get\_contents(get\_parent\_theme\_file\_path() .’/woocommerce/emails/custom-email.php’);

$headers = “Content-Type: text/html\\r\\n”;


//send the email through wordpress

$mailer->send( $recipient, $subject, $body, $headers );

1 Comment
  1. Shortcodes only render in pages and posts. Can you access the shortcode’s callback function directly?


This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer