Set default value for Enity Reference using View and Entity Reference View Widget Checkbox Basically i have a field (in line item(commerce custom product)) with Field type: Entity Reference and Widget:View. The view is a list of terms and has an aditional field type:Entity Reference View Widget Checkbox to provide a checkbox in so user could configure the product.

The whole chain works fine from user point of view but there is no option to set the default value (in UI) and the option to set the default value from hook_form_alter() is not giving the needed result.

This is hook_form_alter:

function test_form_commerce_cart_add_to_cart_form_3_alter(&amp;$form, &amp;$form_state, $form_id){

    $form['line_item_fields']['field_pesonal_data']['und'][0]['field_cover']['#default_value']=6;

}


Please provide a solution. Thx!
Did you try casting the value to a string?  I had to do that when I was setting default values for a user reference field type.  It wouldn't work otherwise. Something like

 $form['line_item_fields']['field_pesonal_data']['und'][0]['field_cover']['#default_value']=(string)6;


Also, I noticed that you had a spelling error.  You had 'field_pesonal_data' It should probably be 'field_personal_data'

Also, I was a little confused by your use of terminology.  You described that the user is configuring the entity reference field on the product.  Did you mean configuring the entity on the line item?  I just wanted to clarify, because if you are modifying the form that governs the adding of products (or product variations in Commerce Kickstart 2.0), you need to use a different form alter call because the product variation creation form uses the inline_entity_form module to manage the specific product variations.

That call is:

function hook_inline_entity_form_entity_form_alter(&amp;$entity_form, &amp;$form_state)


Look at the inline_entity_form.api in the contrib/inline_entity_form folder in Commerce Kickstart 2.0

for modifying a user reference on a product, I did the following:

function bh_vendor_inline_entity_form_entity_form_alter(&amp;$entity_form, &amp;$form_state) {
  global $user;
  if ($entity_form['#entity_type'] == 'commerce_product') {
    $entity_form['vendor_user_reference']['und']['#default_value'] = (string)$user-&gt;uid;
  }
}


My widget I used was a option list.
You have to have the ['und'] or it won't work either.