A
A
Andrej3832021-03-23 13:29:57
WordPress
Andrej383, 2021-03-23 13:29:57

How to make the term of use of the goods in wookomers?

There was such a question. There is a virtual product #1 (this is access to the server for 1 person). He buys it with a period of, for example, 5 days (product attribute). As soon as he bought the product, it becomes unavailable in the store (after all, the quantity is 1 pc). How to make it appear in the store again after 5 days?
PS: Yes, I understand that this is a function of the number of goods in the warehouse and you can manually set 1 in the number of goods in the warehouse. But how to make an automatic binding to the number of days of using the product?

What are some smart solutions or ideas?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pychev Anatoly, 2021-03-23
@pton

At the time of sale or reset, store in the meta field the value (date and time in number format) when the product should reappear.
Once a day, unload from the database for all products for which the date is outdated and change the quantity to the desired one.
Pros: You can set individual times for each product.
Pitfalls: If there are a lot of products, then the update may take time and crash the server. You have to do it through cron. Attention WordPress cron runs at the request of users. If there are no users on the site, the cron will not run. Launching through background tasks is possible, I would choose this option. Although running background tasks is also done through wp cron, the difference is that if there are many tasks, only one is needed to start. Library for background tasks here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question