0

I have an external database (not a Wordpress one) where my client's stock is managed and I need to check the product availability considering this database, not the wordpress' one. My inicial idea is to find where the product is parsed from the database and make an external query to the other database, filling whatever field is to be filled with the product quantity on stock and theoretically all the other validations would work as if this value was the one set on the wordpress database. Is this the best approach to the problem? If so, is there a hook/filter where I can attach my code? Which one? Thank you all in advance

1
  • It seems that this is your first question in this site. Actually it is difficult to answer; your question is quite board and the recommendation to filter or hook into WooCommerce actions would be off topic here as it is third party software. If you could narrow down your problem may be you can help.
    – cybmeta
    Commented Jan 16, 2015 at 18:01

2 Answers 2

1

Your approach is impractical in any site with decent traffic. In that case having real time updates from a DB is the best way to bring your site down. What you need is to check the availability when people at items to carts and then again before the actual checkout.

In addition you can update the current number of items every hour (or faster if you really want to try to be as accurate as possible) with a wordpress cron task, but this number is just to give the user a feeling if he should hurry and buy or he has time to think about it. Just remember that unless you are going to keep some ajax going to update the number, the user will very likely see a stale information as the kids called him (or any other distraction) and he returned only after half an hour later to look at the product.

0

If i correctly understand your question, then i would do it these way:

  1. create api on website ( or create website with api ) wich uses external database, wich you need to take data from
  2. using wp_schedule_event create function wich will fire each hour or day or week to pull data from your api ( external db ). These part i didn't understood, so if you need, for ex., to pull data on post save, then use action save_post, also u can make your own dashboard page ( even form ) wich, on submit or button press, will pull data from api.
  3. Use recived data to change post meta or options or what ever you need

Also, you might skip 1 step and do the connection to external database and pull data from there, but i reccomend api.

3
  • Dear Mr Михаил, thank you for your answear but this is not exactly the way I need, I need to check the product availability in real time. For example, when the user enters the shop page, the ones that are out of stock in the external DB must be marked as out of stock, and this must be checked when he enters the page, not hourly!
    – Gus Campos
    Commented Jan 16, 2015 at 13:14
  • that's not a problem, just run you'r function in action, for example init or wp or some alse action.. in action you could check if( is_shop() ) { // do your stuff } Commented Jan 16, 2015 at 13:37
  • for more info about actions go to codex.wordpress.org/Plugin_API/Action_Reference wp fits best for your needs, but remember that each visitor vich will be loading eny page, each time will make a request to db Commented Jan 16, 2015 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.