'Adding custom fields to woocommerce checkout page disables place order button function
I'm trying to add this basic code to add a new field to the check out page. However, it seems to disable the place order button. Here is the code:
/**
 * Add the field to the checkout
 */
add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
function my_custom_checkout_field( $checkout ) {
    woocommerce_form_field( 'my_field_name', array(
        'type'          => 'text',
        'class'         => array('my-field-class form-row-wide'),
        'label'         => __('Were you assisted with this order?'),
        'placeholder'   => __('Please enter the name of your rep here'),
        ), $checkout->get_value( 'my_field_name' ));
    echo '</div>';
}
Solution 1:[1]
You just need to remember to add the start echo'<div>' tag for your field options div. Otherwise it disables the woo-commerce functionality on the page.
add_action('woocommerce_after_order_notes','my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
//need to remember echo start tag here! 
echo '<div id="my_custom_checkout_field">';
    woocommerce_form_field( 'name_of_child', array(
        'type'          => 'text',
        'class'         => array('my-field-class form-row-wide'),
        'label'         => __('Name of Child'),
        'placeholder'   => __('Enter something'),
        ), $checkout->get_value( 'name_of_child' ));
echo '</div>';
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|---|
| Solution 1 | Zoe stands with Ukraine | 
