In order_new.html, I am using {{var order.getTest()}} to try and get a custom order attribute (special instructions, purchase order, etc). However, I need to pass the order id through to execute my code to return the variables. How can I pass the order id to the function?


public function getTest($orderid)
    $test = "THIS IS A TEST... ORDER ID: " . $orderid;
    return $test;

{{var order.increment_id}} prints the correct order id on the template of the email, however, when I try to add it to the above mentioned function, no value is being passed through. Here's what I've tried on order_new.phtml:

  • {{var order.getTest({{var order.increment_id}})}}
  • {{var order.getTest(var order.increment_id}}
  • {{var order.getTest({{order.increment_id}})}}
  • {{var order.getTest(order.increment_id}}
  • {{var order.getTest({{var order}})}}
  • {{var order.getTest(var order}}
  • {{var order.getTest({{order}})}}
  • {{var order.getTest(order}}

Any help is greatly appreciated. Thanks in advance

  • why do you need to pass the order id to a method that is inside the order model. Can't you just use $this->getId() inside getTest method, since you are getting the value for the current order? – Marius Feb 20 '17 at 22:07
  • @Marius Hmmm that's a good idea, however, it's returning a different order id, not the increment_id. – NotJay Feb 20 '17 at 22:20
  • And $this->getOrderId() doesn't return a value. – NotJay Feb 20 '17 at 22:20
  • 1
    getIncrementId() does work however. Thank you. – NotJay Feb 20 '17 at 22:33

In order_new.html, use:

{{var order.getTest()}}

In Sales/Model/Order.php, use:

public function getTest()
    $orderid = $this->getIncrementId();
    $html = "TEST... The Order ID is: " . $orderid . ". Happy days!";
    return $html;

You can also use getId() which will return the non-increment order id.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.