Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果购物车不为空,则重新引导登录_Php_Wordpress_Woocommerce_Cart - Fatal编程技术网

Php 如果购物车不为空,则重新引导登录

Php 如果购物车不为空,则重新引导登录,php,wordpress,woocommerce,cart,Php,Wordpress,Woocommerce,Cart,如果购物车不是空的,我想在用户登录后将其重定向到购物车页面。我正在尝试: function woocommerce_custom_redirects() { if(!WC()->cart->is_empty() ) wp_redirect( "https://edkasa.com/checkout" ); } add_action('wp_login', 'woocommerce_custom_redirects'); 但这不起作用,我使用的是buddyp

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

function woocommerce_custom_redirects() {

    if(!WC()->cart->is_empty() )
        wp_redirect( "https://edkasa.com/checkout" );
}
add_action('wp_login', 'woocommerce_custom_redirects');
但这不起作用,我使用的是buddypress插件,你知道我哪里出了问题吗。

使用
wp\u redirect()
函数,建议随后显式调用
exit
。有关这方面的更多信息,请参阅

因此,您可以尝试将其添加到代码中。。。比如:

function woocommerce_custom_redirects() {
    ob_start();     // COULD BE A GOOD IDEA
    if ( WC()->cart->get_cart_contents_count() !== 0 || !WC()->cart->is_empty() ) {
        wp_redirect( "https://edkasa.com/checkout" );
        exit;       // VERY VITAL HERE TO EXPLICITLY CALL exit...
    }

}
add_action('wp_login', 'woocommerce_custom_redirects');
使用
wp\u redirect()
函数,建议随后显式调用
exit
。有关这方面的更多信息,请参阅

因此,您可以尝试将其添加到代码中。。。比如:

function woocommerce_custom_redirects() {
    ob_start();     // COULD BE A GOOD IDEA
    if ( WC()->cart->get_cart_contents_count() !== 0 || !WC()->cart->is_empty() ) {
        wp_redirect( "https://edkasa.com/checkout" );
        exit;       // VERY VITAL HERE TO EXPLICITLY CALL exit...
    }

}
add_action('wp_login', 'woocommerce_custom_redirects');

刚刚删除了前面答案的静态链接

function woocommerce_custom_redirects() {
 ob_start();     // COULD BE A GOOD IDEA
 if ( WC()->cart->get_cart_contents_count() !== 0 || !WC()->cart->is_empty() ) {
  global $woocommerce;
  $checkout_url = $woocommerce->cart->get_checkout_url();

    wp_redirect($checkout_url);
    exit;       // VERY VITAL HERE TO EXPLICITLY CALL exit...
 }
}
add_action('wp_login', 'woocommerce_custom_redirects');

刚刚删除了前面答案的静态链接

function woocommerce_custom_redirects() {
 ob_start();     // COULD BE A GOOD IDEA
 if ( WC()->cart->get_cart_contents_count() !== 0 || !WC()->cart->is_empty() ) {
  global $woocommerce;
  $checkout_url = $woocommerce->cart->get_checkout_url();

    wp_redirect($checkout_url);
    exit;       // VERY VITAL HERE TO EXPLICITLY CALL exit...
 }
}
add_action('wp_login', 'woocommerce_custom_redirects');

我正在寻找,但找不到任何地方,因为我可以将空的woocommerce购物车重定向到主页。我只找到指向商店的重定向

这是我发现的,但我不需要重定向到家庭:

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购物车重定向到主页。我只找到指向商店的重定向

这是我发现的,但我不需要重定向到家庭:

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' ) ) );
    }
}
谢谢