Answer the question
In order to leave comments, you need to log in
How to sell digital keys?
Is it possible to implement the sale of digital keys through WordPress so that it would be possible to download a certain number of keys in one go at once, and when buying, only one was issued to the buyer, and the number in stock decreased, so that the same key would not be issued to different people. Maybe there are plugins to implement this?
Answer the question
In order to leave comments, you need to log in
We have already suggested a variant with commercial plug-ins above. If this does not suit you, then you can write yourself.
I will not describe the full development cycle, I will only point out those points that were asked in the question and, in fact, are key, about protection, code optimization, database structures, and so on, think for yourself.
1. Organize the storage of keys.
Since keys are by definition unique but activate a specific product, they must be stored in a separate table linked to the product table via a foreign key. What other fields will be in this table - depends only on the needs of the customer.
2.Organize the sample so that only one buyer can buy one key.
I don’t know how wordpress works, but there is a construction in sql *select ... for update
, which blocks further fetching of rows until the current transaction ends (including both locking and changing the necessary data).
START TRANSACTION;
-- заблокировать нужное
SELECT value FROM counters WHERE id = 1 FOR UPDATE;
-- увеличить значение.
UPDATE counters SET value = value + 1 WHERE id = 1;
COMMIT;
There are paid solutions. I will not provide specific links. You can google for wordpress keys shop plugin .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question