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