建立欄位code筆記

//建立我需要的 field_order_serial
if(!field_info_field('field_order_serial')){
$field = array(
  'field_name' => 'field_order_serial',
  'type' => 'text',
);
field_create_field($field);

// Create the instance on the Commerce Order.
$instance = array(
  'field_name' => 'field_order_serial',
  'entity_type' => 'commerce_order',
  'label' => t('Order Serial'),
  'bundle' => 'commerce_order',
  'required' => TRUE,
  'settings' => array(

  ),
  'widget' => array(
    'type' => 'textfield',
  ),
);
field_create_instance($instance);

}