Skip to content

Instantly share code, notes, and snippets.

@sarangs07
Created May 18, 2020 14:28
Show Gist options
  • Save sarangs07/f1d2f64cf954056ccf341840f54175b3 to your computer and use it in GitHub Desktop.
Save sarangs07/f1d2f64cf954056ccf341840f54175b3 to your computer and use it in GitHub Desktop.
Redirect to Shop or any page if the Cart is empty.
/*
* How to add the custome code.
*
* Please follow below instructions:
* 1. Copy the below code.
* 2. Open your child theme's functions.php file.
* 3. Paste the copied code at the very bottom of it & save the file OR upload it on your server/hosting.
*/
add_filter( 'template_redirect', function (){
if( ! is_checkout() ){
return;
}
if( WC()->cart->is_empty() ){
wp_redirect(wc_get_page_permalink( 'shop' ));
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment