Skip to content

Instantly share code, notes, and snippets.

@Acephalia
Last active April 1, 2023 22:25
Show Gist options
  • Save Acephalia/3474899a67dda404fcd03d478015f286 to your computer and use it in GitHub Desktop.
Save Acephalia/3474899a67dda404fcd03d478015f286 to your computer and use it in GitHub Desktop.
Add Custom Checkout Field Woocommerce
// 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