Skip to content

Instantly share code, notes, and snippets.

@BFTrick
Created May 26, 2016 15:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BFTrick/1c8b4c49c5e5ab667b7ad9a12ae4f524 to your computer and use it in GitHub Desktop.
Save BFTrick/1c8b4c49c5e5ab667b7ad9a12ae4f524 to your computer and use it in GitHub Desktop.
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
Copy link

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