Last active
February 25, 2021 12:53
-
-
Save EngKhaledB/b63942d0239a5557769582e94645027e to your computer and use it in GitHub Desktop.
Allow only Gmail emails on WooComerce checkout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add this code to functions.php | |
add_action( 'woocommerce_after_checkout_validation', 'checkout_allow_only_gmail_emails', 10, 2 ); | |
function checkout_allow_only_gmail_emails( $fields, $errors ) { | |
if ( ! empty( $fields['billing_email'] ) ) { | |
list( $user_id, $domain ) = explode( '@', $fields['billing_email'] ); | |
if ( strtolower( $domain ) != 'gmail.com' ) { | |
$errors->add( 'validation', 'Only Google emails are allowed!' ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment