Get current order object in email footer template


I have a translation suffix for ACF for the customer-invoice.php content based on customers billing and shipping adress, and Im trying to make these translations work for a custom footer template. 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 the language suffix when I echo my ACF-fields doesn’t work.

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.

Any idea how to do this correctly?

user3344734 1 year 2020-07-20T02:11:19-05:00 0 Answers 43 views 0

Leave an answer