Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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 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

    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?

    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

    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

Viewing 5 replies - 1 through 5 (of 5 total)