Skip to main content
replaced http://drupal.stackexchange.com/ with https://drupal.stackexchange.com/
Source Link

You would need to two things to make this happen:

  1. How to programmatically create a custom tokenHow 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.

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.

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.

Source Link
joshmiller
  • 1.5k
  • 9
  • 20

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.