Skip to content

Instantly share code, notes, and snippets.

@woogists
Last active November 7, 2023 12:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save woogists/981c3b405b4288c562a64f59db9c5e13 to your computer and use it in GitHub Desktop.
Save woogists/981c3b405b4288c562a64f59db9c5e13 to your computer and use it in GitHub Desktop.
[Customizing checkout fields using actions and filters] Add a custom checkout field to WooCommerce.
/**
* Add the field to the checkout
*/
add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';
woocommerce_form_field( 'my_field_name', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Fill in this field'),
'placeholder' => __('Enter something'),
), $checkout->get_value( 'my_field_name' ));
echo '</div>';
}
@justcalljarold
Copy link

how can this be a required input and used as details for emailing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment