我只需要在CART Page
中发生这种情况,而无需从购物车菜单或微型购物车中删除商品。
从CART页面中删除最后一个项目(假设购物车现在为空)后,我需要将用户重定向到另一个页面。不幸的是,我的方法无效。
function action_woocommerce_cart_item_removed( $cart_item_key, $instance ) {
global $woocommerce;
if(is_cart() && $woocommerce->cart->cart_contents_count == 0){ //currently in the cart page and the cart is now empty.
wp_redirect('some-page'); //leave the cart page and redirect to another page.
exit();
}
}
add_action( 'woocommerce_cart_item_removed', 'action_woocommerce_cart_item_removed', 10, 2 );