Created
May 18, 2020 14:28
-
-
Save sarangs07/f1d2f64cf954056ccf341840f54175b3 to your computer and use it in GitHub Desktop.
Redirect to Shop or any page if the Cart is empty.
This file contains 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
/* | |
* 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