Get woocommerce current order object in email footer template


I have multilingual ACF option fields with a language code suffix appended to the field name, so in the woocommerce customer-invoice.php file I am outputting fields based on customers billing and shipping address.

Im trying to make these field translations work in my customised woocommerce footer email templates. In my customer-invoice.php file I have set so that an order with order status enquiry loads my custom footer template:

elseif ($order->has_status('enquiry')) {
wc_get_template( 'emails/email-header-quote.php', array( 'email_heading' => $email_heading_quote ) ) ;

This works, but it doesn’t pass the $order object, so I cant get the language suffix in order to get the correct ACF option field.

The only thing that I have managed to have any luck with it is if I add

add_action('woocommerce_email_footer', function ($email) {
if (!isset($GLOBALS['wc_email'])) {
    $GLOBALS['wc_email'] = $email;
}, 1, 1);
do_action( 'woocommerce_email_footer', $email );

To my customer-invoice.php file (doesn’t work if I put it in my function file)

and if I reference it in my customer footer template:

$order = null;

if (isset($GLOBALS['wc_email']) && $GLOBALS['wc_email']->object && $GLOBALS['wc_email']->object instanceof WC_Order) {
$order = $GLOBALS['wc_email']->object;

This brings me the correct translation. The problem is that this will load the default footer template on top of my custom footer template.

What is the best way to pass the $order object to my custom woocommerce email footer template?

user3344734 1 year 2020-07-23T17:10:26-05:00 0 Answers 60 views 0

Leave an answer