woogists
3/11/2018 - 3:15 PM

[Customizing checkout fields using actions and filters] Validate WooCommerce custom checkout field

[Customizing checkout fields using actions and filters] Validate WooCommerce custom checkout field

/**
 * Process the checkout
 */
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');

function my_custom_checkout_field_process() {
    // Check if set, if its not set add an error.
    if ( ! $_POST['my_field_name'] )
        wc_add_notice( __( 'Please enter something into this new shiny field.' ), 'error' );
}