Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I retrieve a JSON of all WooCommerce data on any Wordpress page?

I want to set up a WooCommerce shop for a WordPress site (which I've never done before by the way).

However, I do not want to use any type of WooCommerce generated pages.

What I want is to add/remove products (along with all other relevant product data), create categories, subcategories etc.. using the WooCommerce "control panel" from inside the Wordpress Dashboard and every time I do that, I want a WooCommerce object (containing all that data) to be updated/generated and made available across all (or some specific) pages.

The reason for that is because I want to build everything myself (product pages, cart page, checkout page, category pages, subcategory pages).

In order to populate these pages with the relevant data, however, I'll need to have access to the whole of WooCommerce data from any of those pages.

Some examples will explain better what I'm trying to achieve. (note : I'll be using Javascript and generating everything on the client)

Case #1 Let's say I am in the "Shop" page, and I want to populate a column with all available product categories. I need to be able to do something like that :

var wooCommerceShopData = getAllWooCommerceShopData(); // an Ajax request that will fetch me all that data

var arrayOfAllAvailableCategories = wooCommerceShopData.categories;

Case #2

Now suppose I am in the "sportswear" category. I need to be able to do something like that :

var wooCommerceShopData = getAllWooCommerceShopData();

var productsObjectForCurrentCategory = wooCommerceShopData.categories["sportswear"].products;

Case #3

If I am on a "sportwear"-category product page, I need to be able to do something like that :

var wooCommerceShopData = getAllWooCommerceShopData();

var currentProductData = wooCommerceShopData.categories["sportswear"].products["BLK123XMENSHORTS"];

var currentProductPrice = currentProductData.price;

// etc......

Is this possible and is there an WooCommerce/Wordpress API for that ?

like image 961
Sprout Coder Avatar asked Nov 29 '14 18:11

Sprout Coder


Video Answer


1 Answers

WooCommerce provides a Rest API.

You can find the documentation here:

https://woocommerce.github.io/woocommerce-rest-api-docs/

Hope it helps.

like image 120
XciD Avatar answered Sep 19 '22 00:09

XciD