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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
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