I have a custom post type (product) that have a meta field that
hold’s inventory quantity.
Once an order is made im updating the quantity
`$qty=get_post_meta($post->ID,’stock’,true);
$qty–;
Update_post_meta($post->ID,’stock’,$qty);`
The thing is im afraid that multiple and simultanious calls for this update
Might cause the data to be incorrect If a call will be made while another call is in process…
Is there a way to lock that piece of code and make sure it wont be fired
Simultaniously or am i exadurating in my concerns ?
Well generally there shouldnt be a concern, my issue is why are you getting the quantity and then using it to subtract it and update it again, when everything can be done in one step. I am assuming those 2 methods are making some call to a database. In MYsql you can do something like
That way the deduction happens in your database and you are saving one query…