if cart is empty, the cart page will redirect to shop page in woocommerce?
问题 I am working on wordpress woocommerce I want to redirect the cart page to shop page when the cart page is empty otherwise shows the cart page. Can anyone have the solution ? Here is the code I have tried, but it does not work function my_empty_cart() { global $woocommerce; if (isset( $_GET['empty-cart'] ) ) { wp_safe_redirect( get_permalink( woocommerce_get_page_id( 'product' ) ) ); } } add_action( 'init', 'my_empty_cart' ); 回答1: // old woocommerce : use sizeof( $woocommerce->cart->cart