WooCommerce shop.
Setting “Customer can register while checkout” is ON, so customer have to fill his Name, Phone and Email while checkout (on /checkout/ page).
I want to check this data for errors before registration. So, I try to get this data from $_REQUEST variable or from $fields array from filter “woocommerce_after_checkout_validation”, but I can’t do this.
This is how I try:
add_action( 'woocommerce_before_checkout_registration_form', 'check_request', 1 );
function check_request () {
echo '<pre>'; print_r($_REQUEST); echo '</pre>';
}
/* OUTPUT:
Array
(
[woocommerce-login-nonce] =>
[_wpnonce] =>
[woocommerce-reset-password-nonce] =>
[woocommerce-edit-address-nonce] =>
[save-account-details-nonce] =>
)
*/
And this:
add_filter( 'woocommerce_after_checkout_validation', 'custom_after_checkout_validation', 10, 2);
function custom_after_checkout_validation ($fields, $errors){
if ( empty( $fields['billing_phone'] ) ) {
$errors->add( 'phone validation', 'Phone is empty' );
}
}
/* OUTPUT:
Phone is empty
*/
Please, help me.
2
Answers
Try This
You can verify phone number using sms service and Ajax
Past this code in your functions.php
Note: You have to integrate variable $flag 0 or 1 with SMS service where you can verify the phone numberĀ
If $flag = 0;
https://prnt.sc/rbwxhg
IF $flag = 1;
https://prnt.sc/rbwx1w
I think this is helpful for you