• Resolved hanneslf

    (@hanneslf)


    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://www.ads-software.com/plugins/woocommerce-simply-order-export/

Viewing 15 replies - 1 through 15 (of 37 total)
  • Hi hanneslf,

    Please follow these steps. In below example I am adding payment method field.

    Step 1: Add field to column

    function wpg_add_columns($cols) {
    
    	$cols['wc_settings_tab_payment_method'] = __('Payment Method', 'mytheme');
    	return $cols;
    }
    add_filter('wpg_order_columns', 'wpg_add_columns');

    Step 2: Add same column to settings, so that it will appear in settings page.

    function wpg_add_fields($settings) {
    
    	$settings['payment_method'] = array(
    								'name' => __( 'Payment Method', 'woocommerce-simply-order-export' ),
    								'type' => 'checkbox',
    								'desc' => __( 'Payment Method', 'woocommerce-simply-order-export' ),
    								'id'   => 'wc_settings_tab_payment_method'
    							);
    
    	return $settings;
    
    }
    add_filter('wc_settings_tab_order_export', 'wpg_add_fields');

    Note: Notice that in above step, id attribute is identical to that of array key in step 1. ( wc_settings_tab_payment_method )

    Step 3: Add it to csv.

    function csv_write( &$csv, $od, $fields ) {
    
    	if( !empty( $fields['wc_settings_tab_payment_method'] ) && $fields['wc_settings_tab_payment_method'] === true ){
    		$payment_method = get_post_meta( $od->id, '_payment_method_title', true );
    		array_push( $csv, $payment_method );
    	}
    
    }
    add_action('wpg_before_csv_write', 'csv_write', 10, 3);

    In these 3 steps you can add as many fields you want to add.

    Let me know if you have any further query.

    will this work for custom fields as well? I added a field new_field after the order notes section and need to pull that into the export? Show a quick example?

    This will also work for custom fields.
    Just replace
    get_post_meta( $od->id, '_payment_method_title', true );

    with your meta_key. That’s it.

    Thread Starter hanneslf

    (@hanneslf)

    Brilliant Ankit.
    Thanks for this plugin.
    Hannes

    Hi

    I have added what here its writed for payment metode, and not show in the csv

    in the csv exported only the customer name, amount, phone number

    what I did not do well?

    Hi,

    Have you checked those fields and saved ? Only after saving those settings, it will be possible to extract that field in CSV.

    Let me know your response.

    Regards

    Hi

    Thanks for the great plugin! Everything works fine but I’m not sure how to add more than one field. Could you be so kind and give me an example of the above code when adding more than one field.

    Thanks so much!

    Hi,

    I am currently working on developing a field manager pack for this plugin. It will be basically an add-on for this plugin which will have cluster of fields. I think this should be ready soon, I will let you know once it will be available.

    Thank you

    Thanks for your response. I’m looking forward to this add-on.

    MC-land

    (@michaeliresource)

    can I see an example of the functions.php file code which has more than 1 custom field to it?

    Do you just keep repeating the three steps? I feel like there would be an array you would keep everything together.

    I ‘ve managed to get two extra fields on the admin screen but cant get them written to the csv file. It just ignores them.
    The code worked when I only had one.

    function xxxx_Woo_export_csv_write( &$csv, $od, $fields ) {

    if( !empty( $fields[‘wc_settings_findus_method’] ) && $fields[‘wc_settings_findus_method’] === true ){
    $findus_method = get_post_meta( $od->id, ‘How did you find us’, true );
    array_push( $csv, $findus_method );
    };

    if( !empty( $fields[‘wc_settings_order_id’] ) && $fields[‘wc_settings_order_id’] === true ){
    array_push( $csv, $od->id );
    };

    }
    add_action(‘wpg_before_csv_write’, ‘xxxx_Woo_export_csv_write’, 10, 3);

    This is an example of adding two fields.
    /**
    * Add columns to WooCommerce Simply Order Export
    */

    function f14a_Woo_export_add_col($cols) {

    $cols[‘wc_settings_findus_method’] = __(‘How Did You Find Us’, ‘mytheme’);
    $cols[‘wc_settings_order_id’] = __(‘Order Id’, ‘mytheme’);
    return $cols;
    }
    add_filter(‘wpg_order_columns’, ‘f14a_Woo_export_add_col’);

    /**
    * Add columns to WooCommerce Simply Order Export – settings page
    * Notice that in above step, id attribute is identical to that of array key in step 1
    */
    function f14a_Woo_export_add_fields($settings) {

    $settings[‘findus_method’] = array(
    ‘name’ => __( ‘How Did You Find Us’, ‘woocommerce-simply-order-export’ ),
    ‘type’ => ‘checkbox’,
    ‘desc’ => __( ‘How Did You Find Us’, ‘woocommerce-simply-order-export’ ),
    ‘id’ => ‘wc_settings_findus_method’
    );

    $settings[‘order_id’] = array(
    ‘name’ => __( ‘Order Id’, ‘woocommerce-simply-order-export’ ),
    ‘type’ => ‘checkbox’,
    ‘desc’ => __( ‘Order Id’, ‘woocommerce-simply-order-export’ ),
    ‘id’ => ‘wc_settings_order_id’
    );
    return $settings;

    }
    add_filter(‘wc_settings_tab_order_export’, ‘f14a_Woo_export_add_fields’);

    /**
    * Add columns to WooCommerce Simply Order Export – add to csv
    */
    function f14a_Woo_export_csv_write( &$csv, $od, $fields ) {

    if( !empty( $fields[‘wc_settings_findus_method’] ) && $fields[‘wc_settings_findus_method’] === true ){
    $findus_method = get_post_meta( $od->id, ‘How did you find us’, true );
    array_push( $csv, $findus_method );
    };
    if( !empty( $fields[‘wc_settings_order_id’] ) && $fields[‘wc_settings_order_id’] === true ){
    array_push( $csv, $od->id );
    };

    }
    add_action(‘wpg_before_csv_write’, ‘f14a_Woo_export_csv_write’, 10, 3);

    Thank you Dillx for your cooperation ??

Viewing 15 replies - 1 through 15 (of 37 total)
  • The topic ‘Adding fields’ is closed to new replies.