我正在从事wordpress woocommerce。
我想在购物车为空时将购物车页面重定向到商店页面。使用ajax删除购物车中的商品,因此在删除所有商品之后,我将重定向到商店页面而无需刷新页面。
这是我尝试过的代码,但是不起作用。
function cartitem_after_remove_product($cart_item_key) {
global $woocommerce;
$total_count = $woocommerce->cart->cart_contents_count;
if($total_count == 0)
{
wp_safe_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
}
} add_action('woocommerce_cart_item_removed','cartitem_after_remove_product');