Last active
January 20, 2020 07:09
-
-
Save akshuvo/3b158d2ba456769cc78d98cd182895c1 to your computer and use it in GitHub Desktop.
Redirect when cart is empty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function cart_empty_redirect_to_shop() { | |
global $woocommerce; | |
if ( is_page('cart') and !sizeof($woocommerce->cart->cart_contents) ) { | |
wp_redirect( get_permalink( wc_get_page_id( 'shop' ) ) ); exit; | |
} | |
} | |
add_action('template_redirect', 'cart_empty_redirect_to_shop'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment