WooCommerce检查并在结帐前重定向到登录名 [英] WooCommerce check and redirect to login before checkout

查看:42
本文介绍了WooCommerce检查并在结帐前重定向到登录名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果Woocommerce的默认结帐行为检测到用户未登录,则会在结帐页面上显示创建帐户"框,从而打破了许多Web约定.如果没有任何附加说明,新用户可能不知道该怎么做./p>

我想要的顺序是:

用户结帐>检查登录>

  • 登录后继续结帐.
  • 如果未登录,则重定向到登录/注册页面>进入结帐页面.

基于购物车的WooCommerce登录重定向完全是这种情况

但是,我感到不舒服的是,在上述情况下,一旦用户登录,如果购物车不为空,他/她将被重定向到结帐页面.如果用户的购物车不空,即使他/她还不想结帐,他/她也将根本无法进入MyAccount.

对此有任何想法吗?谢谢大家.

解决方案

在第二个答案中有一个问题,用户登录后始终重定向结帐页面,直到购物车为空,该页面才站在我的帐户页面上!!


此代码将用户重定向到我的帐户页面进行登录,而不是签出(如果用户未登录),然后在自动登录后自动登录重定向到结帐页.
第1步:
将此代码添加到 function.php

  add_action('template_redirect','check_if_logged_in');函数check_if_logged_in(){$ pageid = 68;//您的结帐页面IDif(!is_user_logged_in()&& is_page($ pageid)){$ url = add_query_arg('redirect_to',get_permalink($ pagid),site_url('/my-account/')//您的我的帐户网址);wp_redirect($ url);出口;}} 

步骤2:
/wp-content/plugins/woocommerce/templates/myaccount/my-account.php

的末尾添加此代码

 <?php$ quark_web_solution_redirect = $ _GET ['redirect_to'];如果(isset($ quark_web_solution_redirect)){回声'< script>window.location.href ='.$ quark_web_solution_redirect.'";</script>';}?> 

此帖子来自 Quark Web解决方案的开发人员.
谢谢!!

The default Woocommerce checkout behavior breaks a lot of web conventions by showing the "Create Account" boxes on the checkout page if it detects the user is not logged in. New users may not know what to do without any added instructions.

My desired sequence would be:

User Checkout > Check login >

  • Proceed to checkout if logged in.
  • Redirect to login/register page if not logged in > proceed to the checkout page.

This is EXACTLY the case in WooCommerce login redirect based on cart

However, what I feel uncomfortable is that, in the above case, once the user logged in, he/she will be redirected to the checkout page if the cart is not empty. If the user's cart is not empty, he/she will not be able to go to MyAccount at all even though he/she does not want to checkout yet.

Any idea on this one? Thanks in advanced everyone.

解决方案

In the second answer there is a problem, after loging in the user always redirects checkout page, it does not stand on my-account page until the cart become empty!!


This code redirects the user to my-account page for login instead of checkout if the user is not logged in, then after loging in it automatically redirects to checkout page.
STEP 1:
Add this code in function.php

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

STEP 2:
Add this code at the end of /wp-content/plugins/woocommerce/templates/myaccount/my-account.php

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

This post is from developer of Quark Web Solution.
Thank You!!

这篇关于WooCommerce检查并在结帐前重定向到登录名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆