search
Log In
Welcome to Blogiestools Ask, a blogging community where beginner and professional bloggers come to seek answers from other bloggers’ experiences.

You can ask questions related to starting a blog, monetizing a blog, marketing a blog, managing a blog, fixing a problem, the best web tech tools to use, etc.

Register or log in to ask or answer questions.

Ask a Question

1 vote

I want to allow guest customers to checkout in WooCommerce with specific email domains. I do not want accounts to be registered during checkout with disposable emails.  

in WordPress Problems

1 Answer

0 votes
 
Best answer

To limit WooCommerce account registration to specific email domains for guest customers,  then add the code below to functions.php file in your theme.  

NOTE: Modify the text highlighted in orange with your custom errors text that appears when an email that is not allowed is used. Also, change the allowed email domains.  


add_action('woocommerce_register_post', 'allowed__registration_email_domains_blogies', 10, 3 );

function allowed__registration_email_domains_blogies( $username, $email, $validation_errors ){
    $valid_email_domains = array( 'gmail.com', 'yahoo.com', 'yahoo.co.uk', 'icloud.com'); // Allowed domains
    $valid = false; // sets default validation to false
    foreach( $valid_email_domains as $d ){
        $d_length = strlen( $d );
        $current_email_domain = strtolower( substr( $email, -($d_length), $d_length));
        if( $current_email_domain == strtolower($d) ){
            $valid = true;
            break;
        }
    }

    // Return error message for invalid domains
    if( ! $valid ){
        $error_text = __( "<strong>ERROR</strong>: Only Gmail and  Yahoo, or iCloud emails are allowed.", "woocommerce" );
        $validation_errors->add( 'domain_whitelist_error', $error_text );
    }
}

15.1k points

Related questions

0 votes
1 answer
I need a code to change WooCommerce add cart button text without installing a plugin
asked Nov 8, 2021 in WordPress Problems anonymous
1 vote
1 answer
I want to change the WooCommerce completed order file download link text sent to emails for digital download products
asked Nov 8, 2021 in Fixing Blog Problems anonymous
0 votes
1 answer
I want to modify the WooCommerce checkout loading spinner gif and use my custom icon and text
asked Nov 8, 2021 in WordPress Problems anonymous
0 votes
1 answer
I have a digital marketplace running on WooCommerce. How do I notify vendors when an admin rejects their submitted product?
asked Nov 8, 2021 in WordPress Problems anonymous
1 vote
1 answer
How I do remove WooCommerce Checkout fields that is billing details and order comments without a plugin.
asked Nov 8, 2021 in WordPress Problems anonymous