Title: Adding fields
Last modified: August 22, 2016

---

# Adding fields

 *  Resolved [hanneslf](https://wordpress.org/support/users/hanneslf/)
 * (@hanneslf)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/adding-fields-4/)
 * Hi Ankit,
    I am trying to add fields to the csv file. I can do it using the way
   che_idan suggested b;y editing the plugin directly. But I was hoping to do it
   in the funtions.php file with the wpg_order_columns and wpg_before_csv_write 
   hooks but can’t seem to get it to work.
 * Would you have an example of this. This was my attempt.
 *     ```
       function extra_order_columns($cols) {
       	$cols['wc_settings_tab_customer_address'] = '__( "Address", "woocommerce-simply-order-export" )';
       	return $cols;
       }
       add_filter( 'wpg_order_columns' , 'extra_order_columns' );
   
       function extra_order_columns_data($csv_values) {
       	array_push( $csv_values, self::customer_meta( get_the_ID(), '_billing_address_1' ) );
       	return $csv_values;
       }
       add_filter( 'wpg_before_csv_write' , 'extra_order_columns_data' );
       ```
   
 * [https://wordpress.org/plugins/woocommerce-simply-order-export/](https://wordpress.org/plugins/woocommerce-simply-order-export/)

Viewing 15 replies - 16 through 30 (of 37 total)

[←](https://wordpress.org/support/topic/adding-fields-4/?output_format=md) [1](https://wordpress.org/support/topic/adding-fields-4/?output_format=md)
2 [3](https://wordpress.org/support/topic/adding-fields-4/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/adding-fields-4/page/3/?output_format=md)

 *  [ipekarik](https://wordpress.org/support/users/ipekarik/)
 * (@ipekarik)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-fields-4/page/2/#post-5771427)
 * Hi, Ankit!
 * Could I just nag you a bit with help on setting up the customer billing address
   field?
 * I have this in the add_col function:
 *     ```
       $cols['wc_settings_tab_customer_address'] = __( '<<what is the meta key here?>>', 'mytheme' );
       ```
   
 * I have this in the setttings tab function:
 *     ```
       $settings['customer_address'] = array(
         'name' => __( 'Customer Address', 'woocommerce-simply-order-export' ),
         'type' => 'checkbox',
         'desc' => __( 'Customer Address', 'woocommerce-simply-order-export' ),
         'id' => 'wc_settings_tab_customer_address'
       );
       ```
   
 * I have this in the csv_write function:
 *     ```
       if( !empty( $fields['wc_settings_tab_customer_address'] ) && $fields['wc_settings_tab_customer_address'] === true ){
         $customer_address = get_post_meta( $od->id, '<<what is the meta key here?>>', true );
         array_push( $csv, $customer_address );
       };
       ```
   
 * I’m wondering what the correct meta key is for the billing address?
 *  [ipekarik](https://wordpress.org/support/users/ipekarik/)
 * (@ipekarik)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/adding-fields-4/page/2/#post-5771428)
 * Ah, nevermind I solved it in the meantime. This did the trick:
 * `$customer_address = $od->get_formatted_billing_address();`
 * Nice plugin, btw!
 *  [ankitgadertcampcom](https://wordpress.org/support/users/ankitgadertcampcom/)
 * (@ankitgadertcampcom)
 * [11 years ago](https://wordpress.org/support/topic/adding-fields-4/page/2/#post-5771429)
 * Hi Swissmiss85,
 * I am happy to announce that add-on for this plugin has been released, it is available
   at: [http://sharethingz.com/woocommerce-simply-order-export-add-on/](http://sharethingz.com/woocommerce-simply-order-export-add-on/)
 * Let me know if you have any query.
 * Regards
    Ankit G.
 *  [emmajanedicks](https://wordpress.org/support/users/emmajanedicks/)
 * (@emmajanedicks)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/adding-fields-4/page/2/#post-5771441)
 * Hi Ankit
 * I am trying to add a Product Category to the export file.
 * The result is Product Category appearing on the Order Export page, the title 
   appearing on the Excel sheet, but the column being blank.
 * Do you have any advice? This is my attempt:
 * function wpg_add_columns($cols) {
 *  $cols[‘wc_settings_tab_product_cat’] = __(‘Product Category’, ‘mytheme’);
    return
   $cols; } add_filter(‘wpg_order_columns’, ‘wpg_add_columns’);
 * function wpg_add_fields($settings) {
 *  $settings[‘product_cat’] = array(
    ‘name’ => __( ‘Product Category’, ‘woocommerce-
   simply-order-export’ ), ‘type’ => ‘checkbox’, ‘desc’ => __( ‘Product Category’,‘
   woocommerce-simply-order-export’ ), ‘id’ => ‘wc_settings_tab_product_cat’ );
 *  return $settings;
 * }
    add_filter(‘wc_settings_tab_order_export’, ‘wpg_add_fields’);
 * function csv_write( &$csv, $od, $fields ) {
 *  if( !empty( $fields[‘wc_settings_tab_product_cat’] ) && $fields[‘wc_settings_tab_product_cat’]
   === true ){
    array_push( $csv, strip_tags($od->get_product_cat()) ); }
 * }
    add_action(‘wpg_before_csv_write’, ‘csv_write’, 10, 3);
 *  [emmajanedicks](https://wordpress.org/support/users/emmajanedicks/)
 * (@emmajanedicks)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/adding-fields-4/page/2/#post-5771442)
 * Hi Ankit
 * I am trying to add a Product Category to the export file.
 * The result is Product Category appearing on the Order Export page, the title 
   appearing on the Excel sheet, but the column being blank.
 * Do you have any advice? This is my attempt:
 *     ```
       function wpg_add_columns($cols) {
   
       $cols['wc_settings_tab_product_cat'] = __('Product Category', 'mytheme');
       return $cols;
       }
       add_filter('wpg_order_columns', 'wpg_add_columns');
   
       function wpg_add_fields($settings) {
   
       $settings['product_cat'] = array(
       'name' => __( 'Product Category', 'woocommerce-simply-order-export' ),
       'type' => 'checkbox',
       'desc' => __( 'Product Category', 'woocommerce-simply-order-export' ),
       'id' => 'wc_settings_tab_product_cat'
       );
   
       return $settings;
   
       }
       add_filter('wc_settings_tab_order_export', 'wpg_add_fields');
   
       function csv_write( &$csv, $od, $fields ) {
   
       if( !empty( $fields['wc_settings_tab_product_cat'] ) && $fields['wc_settings_tab_product_cat'] === true ){
       array_push( $csv, strip_tags($od->get_product_cat()) );
       }
   
       }
       add_action('wpg_before_csv_write', 'csv_write', 10, 3);
       ```
   
 *  [ankitgadertcampcom](https://wordpress.org/support/users/ankitgadertcampcom/)
 * (@ankitgadertcampcom)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/adding-fields-4/page/2/#post-5771443)
 * Please change `csv_write` function to.
 *     ```
       function csv_write( &$csv, $od, $field ) {
   
       	switch( $field ) {
   
       		case 'wc_settings_tab_product_cat':
       		 array_push( $csv, strip_tags($od->get_product_cat()) );
       		break;
   
       		default :
       			break;
       	}
   
       }
       add_action('wpg_add_values_to_csv', 'csv_write', 10, 3);
       ```
   
 * Hope this would help.
 * Regards
    Ankit
 *  [amareggae](https://wordpress.org/support/users/amareggae/)
 * (@amareggae)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/adding-fields-4/page/2/#post-5771447)
 * i just tried that one, but still the column is blank. and to add i did purchase
   your add-on plugin. i was sad i didn’t get what i expect to appear on my csv 
   file. 🙁
 *  [ankitgadertcampcom](https://wordpress.org/support/users/ankitgadertcampcom/)
 * (@ankitgadertcampcom)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/adding-fields-4/page/2/#post-5771448)
 * Hi amareggae,
 * Can you please let me know what you are trying to do with the code? Please elaborate.
 *  [Joao Mino](https://wordpress.org/support/users/joaomino/)
 * (@joaomino)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/adding-fields-4/page/2/#post-5771451)
 * Hi [@ankit](https://wordpress.org/support/users/ankit/) Gade,
 * I’m trying to add my custom field on the .csv file using the codes you put here.
   Everything works, but the .csv file that is showing the new column blank.
 * Here is my code:
 *     ```
       function wpg_add_columns($cols) {
   
       	$cols['wc_settings_tab_pessoa_contato'] = __('Pessoa de Contato', 'mytheme');
       	return $cols;
       }
       add_filter('wpg_order_columns', 'wpg_add_columns');
   
       function wpg_add_fields($settings) {
   
       	$settings['pessoa_contato'] = array(
       				'name' => __( 'Pessoa de Contato', 'woocommerce-simply-order-export' ),
       				'type' => 'checkbox',
       				'desc' => __( 'Nome e Telefone da Pessoa de Contato', 'woocommerce-simply-order-export' ),
       				'id'   => 'wc_settings_tab_pessoa_contato'
       				);
   
       	return $settings;
   
       }
       add_filter('wc_settings_tab_order_export', 'wpg_add_fields');
   
       function csv_write( &$csv, $od, $fields ) {
   
       	if( !empty( $fields['wc_settings_tab_pessoa_contato'] ) && $fields['wc_settings_tab_pessoa_contato'] === true ){
       		$pessoa_contato = get_post_meta( $od->id, 'Pessoa de Contato', true );
       		array_push( $csv, $pessoa_contato );
       	}
   
       }
       add_action('wpg_before_csv_write', 'csv_write', 10, 3);
       ```
   
 * I’m not able to write my custom field into the csv file. Could you please help
   me?
 *  [ankitgadertcampcom](https://wordpress.org/support/users/ankitgadertcampcom/)
 * (@ankitgadertcampcom)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/adding-fields-4/page/2/#post-5771452)
 * Hi,
 * You can use the add-on plugin at: [http://sharethingz.com/downloads/woocommerce-simply-order-export-add-on/](http://sharethingz.com/downloads/woocommerce-simply-order-export-add-on/)
 * Once add-on is installed, you can add following code to functions.php file of
   your theme.
 *     ```
       function my_wsoe_hooks() {
       	add_filter( 'wsoe_filter_fields', 'my_add_fields' );
       }
       add_action( 'init', 'my_wsoe_hooks', 8 );
   
       function my_add_fields( $fields ) {
   
       	$fields['wc_settings_tab_pessoa_contato'] = __('Pessoa de Contato', 'woocommerce-simply-order-export');
       }
       ```
   
 * Hope this helps
 *  [Brochurcom](https://wordpress.org/support/users/brochurcom/)
 * (@brochurcom)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/adding-fields-4/page/2/#post-5771453)
 * Hi Ankit.
 * I have used the code from post directly before mine and cannot get the custom
   fields added.
 * Using the code supplied by lumlp lumlp ads the field to the wsoe admin page but
   does not output anything to the CSV.
 * If i remove lump lump code and place your code:
 * function my_wsoe_hooks() {
    add_filter( ‘wsoe_filter_fields’, ‘my_add_fields’);}
   add_action( ‘init’, ‘my_wsoe_hooks’, 8 );
 * function my_add_fields( $fields ) {
 *  $fields[‘wc_settings_tab_pessoa_contato’] = __(‘Pessoa de Contato’, ‘woocommerce-
   simply-order-export’);
    }
 * It breaks the plugin and removes all the options from the addon plugin. It only
   lists the option that are available on the standard plugin.
 * I have the ad on plugin.
 * Any help would be great.
 * Thanks
 *  [ankitgadertcampcom](https://wordpress.org/support/users/ankitgadertcampcom/)
 * (@ankitgadertcampcom)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/adding-fields-4/page/2/#post-5771454)
 * Hi,
 * Can you please use this corrected code and check if issue is resolved?
 *     ```
       function my_wsoe_hooks() {
       	add_filter( 'wsoe_filter_fields', 'my_add_fields' );
       }
       add_action( 'init', 'my_wsoe_hooks', 8 );
   
       function my_add_fields( $fields ) {
   
       	$fields['wc_settings_tab_pessoa_contato'] = __('Pessoa de Contato', 'woocommerce-simply-order-export');
   
       return $fields;
   
       }
       ```
   
 *  [Brochurcom](https://wordpress.org/support/users/brochurcom/)
 * (@brochurcom)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/adding-fields-4/page/2/#post-5771455)
 * Hi Ankit.
 * Thanks for your replay. The ammended code does add the field to soe admin, but
   does not output to csv. The title outputs but not the content.
 * Here is the full code snippit.
 * /*WOCOMMERCE ADD FIELD */
 * /**
 *  * Add the field to the checkout
 *  */
 * add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field’ );
 * function my_custom_checkout_field( $checkout ) {
 *  echo ‘<div id=”my_custom_checkout_field”><h2>’ . __(‘How did you hear about 
   Amawrap?’) . ‘</h2>’;
 *  woocommerce_form_field( ‘hear_about_us’, array(
 *  ‘type’ => ‘text’,
 *  ‘class’ => array(‘my-field-class form-row-wide’),
 *  ‘label’ => __(‘How did you hear about Amawrap?’),
 *  ‘placeholder’ => __(‘E.g Google’),
 *  ), $checkout->get_value( ‘hear_about_us’ ));
 *  echo ‘</div>’;
 * }
 * /**
 *  * Process the checkout
 *  */
 * add_action(‘woocommerce_checkout_process’, ‘my_custom_checkout_field_process’);
 * function my_custom_checkout_field_process() {
 *  // Check if set, if its not set add an error.
 *  if ( ! $_POST[‘hear_about_us’] )
 *  wc_add_notice( __( ‘How did you hear about Amawrap is a required field’ ), ‘
   error’ );
 * }
 * /**
 *  * Update the order meta with field value
 *  */
 * add_action( ‘woocommerce_checkout_update_order_meta’, ‘my_custom_checkout_field_update_order_meta’);
 * function my_custom_checkout_field_update_order_meta( $order_id ) {
 *  if ( ! empty( $_POST[‘hear_about_us’] ) ) {
 *  update_post_meta( $order_id, ‘How did you hear about Amawrap’, sanitize_text_field(
   $_POST[‘hear_about_us’] ) );
 *  }
 * }
 * /* add How did you hear about us to Simply order export */
 * function my_wsoe_hooks() {
    add_filter( ‘wsoe_filter_fields’, ‘my_add_fields’);}
   add_action( ‘init’, ‘my_wsoe_hooks’, 8 );
 * function my_add_fields( $fields ) {
 *  $fields[‘wc_settings_tab_hear_about_us’] = __(‘hear about us’, ‘woocommerce-
   simply-order-export’);
 * return $fields;
 * }
 * Thanks
 *  [ankitgadertcampcom](https://wordpress.org/support/users/ankitgadertcampcom/)
 * (@ankitgadertcampcom)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/adding-fields-4/page/2/#post-5771456)
 * Hi,
 * The issue is with my_custom_checkout_field_update_order_meta function in above
   code.
 * You should not have spaces in meta_key while storing the order meta. You can 
   modify the function code as following.
 *     ```
       function my_custom_checkout_field_update_order_meta( $order_id ) {
   
       if ( ! empty( $_POST['hear_about_us'] ) ) {
   
       update_post_meta( $order_id, 'pessoa_contato', sanitize_text_field( $_POST['hear_about_us'] ) );
   
       }
   
       }
       ```
   
 * This should fetch the order meta, but you will also need to update the meta keys
   in your table to ‘pessoa_contato’
 *  [Brochurcom](https://wordpress.org/support/users/brochurcom/)
 * (@brochurcom)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/adding-fields-4/page/2/#post-5771457)
 * Hi. Thanks for that.
 * I have changed that cade to not having any spaces, but its still not working.
 * The “how did you here about us” custom field including the user inputted data
   does save to the database and I can also see the information within the woocommerce
   order screen.
 * Everything is working except the CSV export option in wsoe. I get the header 
   title but not the actual info inputted into the custom field.
 * Any other ideas?

Viewing 15 replies - 16 through 30 (of 37 total)

[←](https://wordpress.org/support/topic/adding-fields-4/?output_format=md) [1](https://wordpress.org/support/topic/adding-fields-4/?output_format=md)
2 [3](https://wordpress.org/support/topic/adding-fields-4/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/adding-fields-4/page/3/?output_format=md)

The topic ‘Adding fields’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/woocommerce-simply-order-export_339898.
   svg)
 * [WooCommerce Simply Order Export](https://wordpress.org/plugins/woocommerce-simply-order-export/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-simply-order-export/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-simply-order-export/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-simply-order-export/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-simply-order-export/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-simply-order-export/reviews/)

## Tags

 * [extra fields](https://wordpress.org/support/topic-tag/extra-fields/)

 * 37 replies
 * 14 participants
 * Last reply from: [Marie Comet](https://wordpress.org/support/users/chaton666/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/adding-fields-4/page/3/#post-5771464)
 * Status: resolved