Add a field to entity programmatically

Wanting to add field to some entity (we here pick order entity) by code, for example when deploying to production, use this snippet of code and you will have this new field added.

  field_info_cache_clear();

  $order_entity_info = entity_get_info('commerce_order');

  if (field_info_field('field_color_text')) {
    foreach (array_keys($order_entity_info['bundles']) as $bundle) {
      if (empty($instances['commerce_order'][$bundle]['field_color_text'])) {
        $instance = array(
            'field_name' => 'field_color_text',
             'entity_type' => 'commerce_order',
              'label' => 'Color of text',
              'bundle' => $bundle,
              'widget' => array(
                  'type' => 'textfield',
              ),
         );
        field_create_instance($instance);
      }
    }
  }