If you turn on the option to redirect to the cart page after adding a product to the cart, you will have a nice little button that invites you to Continue Shopping. You can change this URL to anything you want!
When the cart is empty, it shows a button to “Return to shop” instead. By default, as it says, it returns to the shop page selected in the settings. But you can change that URL to something else.
To do so, add this code to your functions.php file located in wp-content/themes/your-theme-name/:
This will redirect to the URL specified in the code.
What if you want to dynamically return to the page previously visited?
Use this code instead:
Be aware that it will return to the previous visited page. So if you were on the cart page while it was not empty, and then removed everything in it, the referrer URL will be the non-empty cart page.
You would need to add some additionals check to be sure that the referrer URL is not the cart page.
Contribute to Improving This Blog
Did you enjoy this article? Was it helpful? Contribute to help me writing more articles! The funds collected from this blog are reinvested directly into improving my skills or the blog so that I can provide more and better content!
Make a one-time donation
Make a monthly donation
Make a yearly donation
Choose an amount
Or enter a custom amount
Your contribution is appreciated.
Your contribution is appreciated.
Your contribution is appreciated.
DonateDonate monthlyDonate yearlyDo you prefer using cryptocurrency? I’ve got you covered! You can donate at the following wallets:
- BTC: bc1q87nxpdpqw323ccmerrzyeffs72wnxpw93x7pzk / 17Gtc5e8yoh2LZzokoyK8P5DWbToBwztok
- ETH: 0xA5C89Be1df2896C3942DBEf751cCeacC7929388b
Leave a Reply