2

I'm trying to customize my Woocommerce Emails and I created already a html template for it, which already works.

The Problem that I have is that it's not displaying the woocommerce variable like for example:

  • this way {order_number}
  • or this way {order_shipping_address}

I always have to put them like this:

<?php echo $order->billing_last_name; ?>

Below is a snippet how the HTML Code looks like:

<span data-key="1468270_order_number">Bestellnr.:</span> #<?php echo $order->id; ?>

So it's plain html file with this php variable at the places where I need them. I put the html file into Woocommerce > Settings > E-Mails > New Order

Do I have to wrap it all into a php file or how do I get variables like {order_number} working. On this related Woocommerce documentation there are a lot of Variables without, but I can't make them work.

How can I use them?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
limilo
  • 327
  • 3
  • 17

1 Answers1

2

The placeholder {order_number} (or some other ones) are only used in emails subject settings. Have a look to "Get custom email placeholder value on Woocommerce custom email content" related answer thread…

So it's not a variable but a placeholder and can not be used on Woocommerce email templates (or available hooks).

Also your question code is outdated since Woocommerce 3 as object properties are protected and not anymore accessible directly… You need to use available methods instead (see CRUD Objects):

  • For the Order ID, use $order->get_id()
  • For the Order Number, use $order->get_order_number()

So in your code:

<span data-key="1468270_order_number">Bestellnr.:</span> #<?php echo $order->get_order_number(); ?>

But to use those methods, the $order Object need to be defined in the template (or the hook).


Related threads:

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399