如果购物车不为空,则Woocommerce登录重定向 [英] Woocommerce login redirect if cart not empty

查看:112
本文介绍了如果购物车不为空,则Woocommerce登录重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果购物车不为空,我想在用户登录后将其重定向到购物车页面。我正在尝试:

I want to redirect the user to cart page after he logs in if the cart is not empty. I am trying this:

function woocommerce_custom_redirects() {

    if(!WC()->cart->is_empty() )
        wp_redirect( "https://edkasa.com/checkout" );
}
add_action('wp_login', 'woocommerce_custom_redirects');

但这无法正常工作,我使用的是buddypress插件,不知道我要去哪里了。 / p>

But this is not working, I am using buddypress plugin, any idea where am I going wrong.

推荐答案

我正在寻找并且找不到任何地方,因为我可以将空的woocommerce购物车重定向到首页。我只找到进入商店的重定向。

I am looking for and can not find anywhere as I can redirect the empty woocommerce cart to the homepage. I only find redirects that go to the store.

这是我发现的内容,但我无需重定向到家:

This is what I find, but I do not need to redirect to the home:

add_action("template_redirect", 'redirection_function');
function redirection_function(){
    global $woocommerce;
    if( is_cart() && WC()->cart->cart_contents_count == 0){
        wp_safe_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
    }
}

谢谢

这篇关于如果购物车不为空,则Woocommerce登录重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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