首页 > 解决方案 > WooCommerce 登录“以访客身份继续”按钮网关

问题描述

我有这串代码可以更改默认的 WooCommerce 结帐行为,当一个人在购物车中并单击“继续结帐”时,它会将他们重定向到 WooCommerce“我的帐户”登录页面。然后他们登录并重定向到结帐页面。我的问题是是否有一种方法可以实现这种行为,但允许人们通过在“以访客身份继续”的表单中添加一个按钮来绕过登录。所以客户可以在登录页面点击这个按钮,绕过确保客户登录的代码。

谢谢您的帮助!!!

add_action('template_redirect','check_if_logged_in');
    function check_if_logged_in()
    {
        $pageid = 48; // your checkout page id
        if(!is_user_logged_in() && is_page($pageid))
        {
            $url = add_query_arg(
                'redirect_to',
                get_permalink($pagid),
                site_url('/account/') // your my acount url
            );
            wp_redirect($url);
            exit;
        }
        if(is_user_logged_in())
        {
        if(is_page(50))//my-account page id
        {

            $redirect = $_GET['redirect_to'];
            if (isset($redirect)) {
            echo '<script>window.location.href = "'.$redirect.'";</script>';
            }

        }
        }
    }

标签: wordpressauthenticationwoocommerceaccount

解决方案


推荐阅读