结账时将 Woocommerce 来宾域列入白名单

发布于 2025-01-13 15:08:53 字数 250 浏览 0 评论 0原文

我需要仅为访客用户创建一个 woocommerce 商店(由于我客户公司的规定,无法进行客户注册)。 有什么办法可以将客户地址域限制为特定域吗?

我的客户希望我为他的员工开设一家 woocommerce 礼品店(一家为公司员工提供免费赠品的“商店”),并且只有在结账表单中提供带有公司域名的电子邮件地址后才可以结账。

有没有办法将访客结账表单中电子邮件字段中的一两个特定域列入白名单?

谢谢你的帮助, 克日谢克

I need to create a woocommerce shop for guest users only (customer registration will not be possible due to my clients company regulations).
Is there any way to restrict customer address domain to a specific domain?

My clinet wants me to make a woocommerce gift shop for his employees (a "shop" with free swag items for company workers), and checkout should be possible only after providing email address with companys domain in checkout form.

Is there any way to whitelist only one or two specific domain in email field in guest checkout form?

Thenk you for your help,
Krzysiek

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

著墨染雨君画夕 2025-01-20 15:08:53

将以下函数放入您的functions.php - https://prnt.sc/O2V_i9B-Frf-

add_action('woocommerce_checkout_process', 'check_domain_email_addresses');
function check_domain_email_addresses() { 
    $email = $_POST['billing_email'];
    //Replace with your domains
    $allowed = [
        'gmail.com',
        'yahoo.com',
    ];
    // Make sure the address is valid
    if (filter_var($email, FILTER_VALIDATE_EMAIL))
    {
        // Separate string by @ characters (there should be only one)
        $parts = explode('@', $email);

        // Remove and return the last part, which should be the domain
        $domain = array_pop($parts);

        // Check if the domain is in our list
        if ( ! in_array($domain, $allowed))
        {
            wc_add_notice( 'Use company email address', 'error' );
        }
    }    
}

Place the following function in your functions.php - https://prnt.sc/O2V_i9B-Frf-

add_action('woocommerce_checkout_process', 'check_domain_email_addresses');
function check_domain_email_addresses() { 
    $email = $_POST['billing_email'];
    //Replace with your domains
    $allowed = [
        'gmail.com',
        'yahoo.com',
    ];
    // Make sure the address is valid
    if (filter_var($email, FILTER_VALIDATE_EMAIL))
    {
        // Separate string by @ characters (there should be only one)
        $parts = explode('@', $email);

        // Remove and return the last part, which should be the domain
        $domain = array_pop($parts);

        // Check if the domain is in our list
        if ( ! in_array($domain, $allowed))
        {
            wc_add_notice( 'Use company email address', 'error' );
        }
    }    
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文