// Function to check starting char of a string function startsWith($haystack, $needle){ return $needle === '' || strpos($haystack, $needle) === 0; } // Custom function to display the Billing Address form to registration page function zk_add_billing_form_to_registration(){ global $woocommerce; $checkout = $woocommerce->checkout(); ?> <?php foreach ( $checkout->get_checkout_fields( 'billing' ) as $key => $field ) : ?> <?php if($key!='billing_email'){ woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); } ?> <?php endforeach; } add_action('woocommerce_register_form_start','zk_add_billing_form_to_registration'); // Custom function to save Usermeta or Billing Address of registered user 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');
In case of any complain or © copyright or issues please check disclaimer page for faster resolutions.
Block malicious web traffic
Sucuri firewall The internet is full of malicious actors. There are low-level annoyances like “scriptread more...
Verify that Google can find your page
Google Search console Google Search Console is a free tool from Google that helps youread more...
E-commerce webshop
E-commerce is a booming industry worldwide. The advent of the internet and the rapid, sustainedread more...
Het snelste en beste webshopplatform Woocommerce
In case of any complain or © copyright or issues please check disclaimer page forread more...
Wat is het verschil tussen UX en UI?
UI-design en UX-design In de wereld van webdesign, maar ook in het ontwikkelen van softwareread more...
Google analytics is a free service provided by Google
Google Analytics Google analytics is a free service provided by Google that helps webmasters, siteread more...
Every website needs hosting
SiteGround hosting Every website needs hosting. Unless you happen to operate a web hosting agency,read more...
Search engine optimization by Yoast
Yoast Plugin Search Engine Optimization (SEO) can be a very technical field. It is alsoread more...
Why should you use Cloudways?
Cloudways hosting Web hosting is an essential service for any internet-based or internet-interfaced business. Whetherread more...
WP Rocket is the best way to boost your site
WP Rocket Plugin WP Rocket is a WordPress plugin that facilitates faster page loads andread more...
Create a multilingual wordpress site
Translatepress plug-in The internet is truly global in nature. An internet user in the Netherlandsread more...