Jump to content


alexpaul

Member Since 05 Mar 2019
Offline Last Active Aug 07 2019 05:11 AM
-----

Topics I've Started

Adding custom fields error

07 August 2019 - 05:11 AM

Can anyone tell me how to add custom fields on the registration page as I am having an error in the code

function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
      if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) {
             $validation_errors->add( 'billing_first_name_error', __( '<strong>Error</strong>: First name is required!', 'woocommerce' ) );
      }
      if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) {
             $validation_errors->add( 'billing_last_name_error', __( '<strong>Error</strong>: Last name is required!.', 'woocommerce' ) );
      }
         return $validation_errors;
}
add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 );

The reference tutorial I have see WooCommerce form and implemented all the steps following this tutorial