Print commerce pricing attributes to email receipt Users cannot see what size or color shirt they purchased in the email receipt because tokens won't print the attribute fields provided by Commerce Product Attributes / Commerce Pricing Attributes / Commerce Product Option combo.


User selects shirt size: XL and color: Green
Both fields can be previewed during checkout.
Email receipt received doesn't show any attributes, user cannot check what size/color they ordered.
(All this can be achieved using default CCK fields under product type, but we're using the combination mentioned above for multiple reasons, many products got different option sets to chose from and certain attributes selected adds extra price to total, like eg size: XXXL costs extra $3+ and this cannot be achieved with default fields).


One of the tokens I found is like eg. [commerce-order:commerce-line-items:0:commerce-pricing-attributes] and email on checkout prints it like this:

Product: BK Test

a:1:{s:9:"coveralls";a:8:{s:25:"field_coverall_embroidery";N;s:25:"field_coverall_text_color";N;s:10:"field_font";N;s:16:"field_shirt_name";N;s:16:"field_patch_side";N;s:12:"field_length";s:1:"2";s:21:"field_coveralls_color";s:1:"4";s:19:"field_coverall_size";s:2:"16";}}


Also more tokens available at admin/help/token like eg.: Attributes  [commerce-line-item:commerce-product:field_attributes]  Pricing Attributes field. and combining them with [commerce-order:commerce-line-items:0:commerce-product] won't work, already tried dozens of variations.

E.g. in Order's view page I addded the view Commerce Line Item: Product Attributes and it displays correctly.



How to print this in the email receipt?
&lt;?php

/**
 * Implements hook_token_info().
 */
function mymodule_token_info(){
    $info['tokens']['commerce-order']['line_item_detail'] = array(
        'name' =&gt; t('Line Item Product Detail List'),
        'description' =&gt; t('List all the Product Line Item Detail of the order')
    );
    return $info;
}

/**
 * Implements hook_tokens().
 */
function mymodule_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();

  if($type == 'commerce-order'){
    $order = $data['commerce-order'];
    $order_wrapper = entity_metadata_wrapper('commerce_order',$order);
    $lineItems = $order_wrapper-&gt;commerce_line_items-&gt;value();
    $lineItemArray = array();
    foreach($lineItems as $key =&gt; $value){
        $line_item_wrapper = entity_metadata_wrapper('commerce_line_item',$value);
        if($line_item_wrapper-&gt;type-&gt;value()=='product'){
            $product_title = $line_item_wrapper-&gt;commerce_product-&gt;title-&gt;value();
            $quantity = $line_item_wrapper-&gt;quantity-&gt;value();
            $lineItemArray[] =  $product_title.' x '.$quantity;
        }
    }

    foreach ($tokens as $name =&gt; $original) {
      switch ($name) {
        case 'line_item_detail':
            $variables = array(
                'items' =&gt; $lineItemArray,
                'type' =&gt; 'ul',
            );
            $replacements[$original] = theme('item_list', $variables);
            break;
      }
    }
  }
  return $replacements;
}


This is the sample code. 

You can modify the result you want at hook_tokens().

I hope this will help you.