1

How to fetch manual flate rate token on replacement pattern

I added Flate Rate cost manually on orders, but I don't find this token on REPLACEMENT PATTERNS. How to fetch this token for my invoice?

here screenshot that I did enter image description here

enter image description here enter image description here

1

You would need to two things to make this happen:

  1. How to programmatically create a custom token. And you'll definitely want to read the API docs on the relevant hook function.

  2. How to get at the line item given an order.

Let's assume your token has an $order object inside the $data variable. The next step would be to use entity metadata wrappers to pull in all the information, including line items.

<?php
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
  $line_item = $line_item_wrapper->value();
}
?>

Your shipping line item is in there. dpm($line_item); to find it and then construct your token output.

|improve this answer|||||
  • Thanks a lot joshmiller, but i'm a programmer and need more time to learn. I guess and I wish this token show up when click replacement pattern. – masmalik Feb 5 '16 at 19:48
  • 1
    If you're using rules, you could always "fetch an entity by id" and actually fetch the shipping line item based on the order field. Anything brought into scope for rules would show up as a token. – joshmiller Feb 5 '16 at 19:56

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.