Last active
April 1, 2023 22:25
-
-
Save Acephalia/3474899a67dda404fcd03d478015f286 to your computer and use it in GitHub Desktop.
Add Custom Checkout Field 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
// Add custom checkout field | |
add_action('woocommerce_after_order_notes', 'howd_you_find_us_bro'); | |
function howd_you_find_us_bro($checkout) { | |
echo '<div id="hdfoamb"><h3>' . __('How did you find my business?') . '</h3>'; | |
woocommerce_form_field( 'customer_acquisition', array( | |
'type' => 'textarea', | |
'class' => array('my-field-class form-row-wide'), | |
'label' => __(''), | |
'placeholder' => __('Please let us know how you found our business.'), | |
), $checkout->get_value( 'customer_acquisition' )); | |
echo '</div>'; | |
} | |
// Save custom checkout field | |
add_action('woocommerce_checkout_update_order_meta', 'howd_you_find_us_bro_update_order_meta'); | |
function howd_you_find_us_bro_update_order_meta($order_id) { | |
if ($_POST['customer_acquisition']) { | |
update_post_meta($order_id, 'Customer Acquisition', esc_attr($_POST['customer_acquisition'])); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment