Skip to content

Instantly share code, notes, and snippets.

@akshuvo
Last active January 20, 2020 07:09
Show Gist options
  • Save akshuvo/3b158d2ba456769cc78d98cd182895c1 to your computer and use it in GitHub Desktop.
Save akshuvo/3b158d2ba456769cc78d98cd182895c1 to your computer and use it in GitHub Desktop.
Redirect when cart is empty
<?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