Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add a "How did you hear about us" field in WooCommerce
<?php
// Filter the checkout fields
add_filter( 'woocommerce_checkout_fields', 'patricks_woocommerce_checkout_fields' );
// add a "how did you hear about us" field - $fields is passed via the filter
function patricks_woocommerce_checkout_fields( $fields ) {
// add the field
$fields['order']['hear_about_us'] = array(
'type' => 'select',
'class' => array( 'form-row-wide' ),
'label' => 'How did you hear about us?',
'options' => array(
'default' => '--select--',
'tv' => 'TV',
'radio' => 'Radio',
'billboards' => 'Billboards',
'podcasts' => 'Podcasts'
)
);
return $fields;
}
@marwa1100

This comment has been minimized.

Copy link

@marwa1100 marwa1100 commented Apr 11, 2018

thanks for the code.
but this warning appears after writing the code

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\wp2\wordpress\wp-content\plugins\woocommerce\templates\checkout\form-billing.php on line 43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.