How can I get an entityform attached to an order in drupal commerce? I'm trying to append an entityform to an order in Drupal commerce. I included the several attempts in my code snippet. Version 1 just throws the following error:

Fatal error: Cannot use object of type EntityValueWrapper as array in /sites/all/modules/kalamuna/tb_commerce_panes/tb_commerce_panes.module on line 374


I tried two other attempts. Version 2 and 3 show up in $order, but when I get to the checkout page and var_dump $order it isn't there. Any ideas why?

function commerce_panes_custom_submit($form, &amp;$form_state, $checkout_pane, $order) {
  // Strip out the entityform type.
  $values = $form_state['values'];
  $entityform_type_name = $values['entityform_bundle'];

  // Create a new entityform from the remaining fields.
  global $user;
  $form = new Entityform(
    array(
      'type'     =&gt; $entityform_type_name,
      'created'  =&gt; time(),
      'changed'  =&gt; time(),
      'language' =&gt; LANGUAGE_NONE,
      'uid'      =&gt; 2
    )
  );

  // The process the rest entityform fields.
  foreach ($values as $k =&gt; $v) {
    if (strstr($k, 'field_')) {
      $form-&gt;$k = $v;
    }
  }

  //Version 1 - Original
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $order_wrapper-&gt;field_tb_registration_forms[] = $form;
  $order_wrapper-&gt;save();

  //Version 2 - Modified Original
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $node = $order_wrapper-&gt;values();
  $node-&gt;field_tb_registration_forms[] = $form;
  $order_wrapper-&gt;save();

  //Version 3 - modify $order and save it
  $order-&gt;field_tb_registration_forms = $form;
  commerce_order_save($order);

}
Have you tried first checking to make sure $order is set? If not then load cart from $user->id first and then wrap it.