How can i add billing address in the registration form?
-
Hello, currently I am using this code but i want all fields to be required to complete registration. How can i do this?
The code I’m using
function zk_save_billing_address($user_id){ global $woocommerce; $address = $_POST; foreach ($address as $key => $field){ if(startsWith($key,'billing_')){ // Condition to add firstname and last name to user meta table if($key == 'billing_first_name' || $key == 'billing_last_name'){ $new_key = explode('billing_',$key); update_user_meta( $user_id, $new_key[1], $_POST[$key] ); } update_user_meta( $user_id, $key, $_POST[$key] ); } } } add_action('woocommerce_created_customer','zk_save_billing_address'); // Registration page billing address form Validation function zk_validation_billing_address(){ global $woocommerce; $address = $_POST; foreach ($address as $key => $field) : // Validation: Required fields if(startsWith($key,'billing_')){ if($key == 'billing_country' && $field == ''){ $woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please select a country.', 'woocommerce' ) ); } if($key == 'billing_first_name' && $field == ''){ $woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter first name.', 'woocommerce' ) ); } if($key == 'billing_last_name' && $field == ''){ $woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter last name.', 'woocommerce' ) ); } if($key == 'billing_address_1' && $field == ''){ $woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter address.', 'woocommerce' ) ); } if($key == 'billing_city' && $field == ''){ $woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter city.', 'woocommerce' ) ); } if($key == 'billing_state' && $field == ''){ $woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter state.', 'woocommerce' ) ); } if($key == 'billing_postcode' && $field == ''){ $woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter a postcode.', 'woocommerce' ) ); } /* if($key == 'billing_email' && $field == ''){ $woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter billing email address.', 'woocommerce' ) ); } */ if($key == 'billing_phone' && $field == ''){ $woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter phone number.', 'woocommerce' ) ); } } endforeach; } add_action('register_post','zk_validation_billing_address');
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘How can i add billing address in the registration form?’ is closed to new replies.