custom field in product type not showing in line item drupal ive created custom fields in my product type.



then i have this code under my custom module

global $user;
$order = commerce_cart_order_load($user-&gt;uid);
if($order) {
     $line_item_list = $order-&gt;commerce_line_items["und"];
     foreach ($line_item_list as $key =&gt; $value) {
         $line_item = commerce_line_item_load($value["line_item_id"]);
         drupal_set_message('&lt;pre&gt;' . print_r($line_item, TRUE) . '&lt;/pre&gt;');
     }
}


i tried to print per line item to, but i cant see my custom field in the print...

anyone experienced this?
You added the fields to the commerce product entity (commerce_product), not the line item entity (commerce_line_item).

That is why the fields don't show on your line item entity.

The line item entity contains a product reference field (commerce_product) referencing the associated product, you will need to inspect that to get the fields from the product.

e.g:

$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
// Get product field value from line item
foreach ($order_wrapper-&gt;commerce_line_items as $delta =&gt; $line_item_wrapper) {
  // If line item is a commerce product type
  if (in_array($line_item_wrapper-&gt;type-&gt;value(), commerce_product_line_item_types())) {
    // Fetch duration value on product.
    $duration = $line_item_wrapper-&gt;commerce_product-&gt;field_subscription_duration_2-&gt;value();
    // Get raw values
    // $duration = $line_item_wrapper-&gt;commerce_product-&gt;field_subscription_duration_2-&gt;raw();
    drupal_set_message($duration);
  }
}