• 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 7 replies - 31 through 37 (of 37 total)
  • ankitgadertcampcom

    (@ankitgadertcampcom)

    As suggested earlier, have you modified the meta_key “How did you hear about Amawrap” to “pessoa_contato” in database?

    Brochurcom

    (@brochurcom)

    Hi Ankit

    Yes i changed the function to having no spaces and also the meta keys. Still no joy.

    Ankit. This is the full code i ihave in my themes function.php. Should i be adding the field to a CSV output function??

    /*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, ‘hear_about_us’, 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;

    }

    I have no code elsware in the wp website regarding adding the field to wsoe.

    Hope that makes sence.
    Thanks

    ankitgadertcampcom

    (@ankitgadertcampcom)

    Hi,

    You do not need to add anything in code to output CSV, placing this code in functions.php and selecting the field to output in csv from Woocommerce > Settings > Order Export should add it to csv.

    If it does not work, can you please share the wp-admin and FTP details of your website with me to be of better help?

    You can send the details on my facebook page here.

    Brochurcom

    (@brochurcom)

    Hi Ankit.

    For you so much for your time and help with this. I have gone aver all the instructions again redoing the code and all is now working fine.

    Thanks again.

    Hi, i’m trying to add custom field to my export : _booking_start and _booking_end with help of code previously posted on this topic, but unfortunaly, it doesn’t work.
    Can you help me to find the right way ? thanks.

    Can you please open a new topic? This topic is already closed.

    Also, please let me know which code you referred?

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