WooCommerce downloads products from a third-party API

I am just starting out with woocommerce. In accordance with the documentation, we need to import products into our database, which should be listed on our website. Basically, the application we are developing acts like an application where the role of the database is very minimal. The Vendor app will provide an API for logging in, logging out, a list of products, and more. All I have to do is integrate these APIs into my woocommerce app. What is the best way to do this? Is there any woocommerce hook to achieve this? Is there a way to get products from the API, not from the database?

+4
source share
2 answers

Yes, there are many ways to achieve your goal. The best and with miniature efforts and high performance. You can get the API response in memory instead of the database, and then save it to Redis cache.

Redis cache exipre for the specified period of time, and then again call the API, and the cache will be updated. You can schedule the cache frequency based on your latency.

thanks

0
source

Woocommerce has a REST API that works quite well. If I understand correctly, you want to get products from an external source and โ€œshowโ€ them in your Woocommerce application, I think you should first โ€œimportโ€ them into the WP database, you cannot skip this step. I donโ€™t think you can directly connect Woocommerce to your suppliers database.

So, you can use the provided REST API to import your supplier products into your toilet. You can easily create a product in Woocommerce using Curl:

curl -X POST https://example.com/wp-json/wc/v2/products \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Premium Quality", "type": "simple", "regular_price": "21.99", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", "position": 0 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", "position": 1 } ] }' 

See the full API Docs for more information.

EDIT:

I just remembered that there is a tool called WP All Import that can help you with this task. As far as I know, you can schedule automatic imports from external XML / CSV sources. You can update all kinds of WP objects, such as WC Products. Maybe worth a look.

0
source

Source: https://habr.com/ru/post/1269438/


All Articles