I’ve recently watched The Queen’s Gambit on Netflix and that has awoken in me the will to play some more chess again as an adult and learn more about it, and be fascinated by this beautiful game again. I have always liked chess since I was a child. I can remember spending time playing it with my cousin at home. It was such a hard game back then, I could barely understand the moves.
So I started looking for chess sets that I could purchase online and I stumbled upon a website from UK which had most of their sets, boards, and pieces, sold out. The Out of Stock string read “Out of Stock because of The Queen’s Gambit”.
At first, I found that funny. I then explored further the website to find out that some products were priced over 1000 GBP and still out of stock because of the TV show. I find it quite hard to believe that someone who watched the show decided to spend over 1000 GBP for a chess board or some pieces. This gave me the idea to write this article.
How can you conditionally change the Out of Stock string based on the product price? Let’s find out!
Setting Up The Board Code
Before you make any code changes, have a backup of your site. This will help you restore things in case of unforeseen errors. I recommend using Jetpack Backup for real-time backups and one-click restores.
As usual, we need to edit some code, so open your wp-content/themes/your-child-theme-name/functions.php file and add this code at the end of it:
This code is simple and quick to change. On line 3 you can set the maximum product’s price. Anything below that value will use the custom Out of stock string instead of the default one. Make sure to also change the “Out of stock” string in the condition on line 3 to your current string, in case you are using a language different than English.
On line 4 instead, you can set your custom Out of stock string. The result will look like this:
This little trick allows you to gauge interest and keep momentum with your sales, like this chess shop did, but in a more realistic way!
How are you using this snippet? What is your custom Out of stock string, and how is it helping you? Let me know in the comments!
Leave a Reply