Created
May 26, 2016 15:19
-
-
Save BFTrick/1c8b4c49c5e5ab667b7ad9a12ae4f524 to your computer and use it in GitHub Desktop.
Add a "How did you hear about us" field in WooCommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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