Add a custom field to the WooCommerce checkout page
This code snippet adds a custom field to the checkout page in WooCommerce. The field is a text input, and it is displayed after the order notes section.
PHP
add_action( 'woocommerce_after_order_notes', 'custom_checkout_field' );
function custom_checkout_field( $checkout ) {
echo '<div id="custom_checkout_field"><h2>' . __('Custom Field') . '</h2>';
woocommerce_form_field( 'custom_field_name', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Fill in this field'),
'placeholder' => __('Enter something'),
), $checkout->get_value( 'custom_field_name' ));
echo '</div>';
}
Snippet Feedback
Did this snippet work for you? Do you have any questions about this snippet? Leave some feedback below.
SHARED BY
1 Views