Skip to content

Instantly share code, notes, and snippets.

@EngKhaledB
Last active February 25, 2021 12:53
Show Gist options
  • Save EngKhaledB/b63942d0239a5557769582e94645027e to your computer and use it in GitHub Desktop.
Save EngKhaledB/b63942d0239a5557769582e94645027e to your computer and use it in GitHub Desktop.
Allow only Gmail emails on WooComerce checkout
<?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