How to Edit the Out of Stock String Conditionally

A chess board focusing on the King

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

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:

Part of the single product page showing a custom Out of stock string.

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!

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!

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

¤5.00
¤15.00
¤100.00
¤5.00
¤15.00
¤100.00
¤5.00
¤15.00
¤100.00

Or enter a custom amount


Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

Do you prefer using cryptocurrency? I’ve got you covered! You can donate at the following wallets:

  • BTC: bc1q87nxpdpqw323ccmerrzyeffs72wnxpw93x7pzk / 17Gtc5e8yoh2LZzokoyK8P5DWbToBwztok
  • ETH: 0xA5C89Be1df2896C3942DBEf751cCeacC7929388b


More Posts That You Might Like…


Leave a Reply

Categories

Newsletter

Receive new articles from this blog directly in your inbox!

No spam guaranteed!

Blog at WordPress.com.

%d bloggers like this: