How to redirect page to shop page when last item removed from cart in woocommerce using ajax?
I am tried below code:
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' );
2
Answers
You can do this via Javascript. WooCommerce has several custom events built in. Your own script can listen to these events and run your own code when they are triggered. One idea would be to check for the class "cart-empty" on updated_cart_totals.
You have to add this code into you function.php file (your theme):