WooCommerce load products from thrid party API WooCommerce load products from thrid party API wordpress wordpress

WooCommerce load products from thrid party API


Yes there is lots of ways to achieve your goal. The best and with minial efforts and high performance. You can fetch API's response in memory instead of database and then store it to Redis cache.

Redis cache exipre in a specified time interval then again call will be made to API and cache will update. You can schedule frequency of caching based on your latency.

Thanks


Woocommerce has a REST API that works quite well. If I understood right you want to fetch the products from an external source and "show" them to your Woocommerce app, I think you must "import" them to the WP database first, you can't skip that step. I don't think you can connect Woocommerce to your vendors database directly.

So for importing your vendors products into your WC you can use the provided REST API. 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 full API Docs for more information.

EDIT:

I've just remembered that there is a tool called WP All Import that may help you a lot accomplishing this task. As far as I know you can schedule automatic imports from XML/CSV external sources. You can update all kind of WP objects such as WC Products. Might be worth it taking a look.