How to get JSON of all WooCommerce data on any Wordpress page?

I want to create a WooCommerce store for a WordPress site (which I have never done before).

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

I want to add / remove products (along with all other relevant product data), create categories, subcategories, etc. using the WooCommerce control panel from inside the Wordpress panel, and every time I do this, I want a WooCommerce object (containing all this data), which will be updated / generated and provided on all (or some specific) pages.

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

However, in order to populate these pages with relevant data, I will need to access all WooCommerce data from any of these pages.

Some examples will better explain what I'm trying to achieve. (note: I will use Javascript and generate everything on the client)

Case # 1 Let's say I'm on the Shop page and I want to populate the column with all available product categories. I need to do something like this:

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

var arrayOfAllAvailableCategories = wooCommerceShopData.categories;

Case No. 2

Now suppose I'm in the sportswear category. I need to do something like this:

var wooCommerceShopData = getAllWooCommerceShopData();

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

Case No. 3

If I'm on the sportswear product page, I need to do something like this:

var wooCommerceShopData = getAllWooCommerceShopData();

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

var currentProductPrice = currentProductData.price;

// etc......

Is this possible, and is there a WooCommerce / Wordpress API for this?

+4
2
+4

, , REST API DOCUMENTATION Woocommerce.

0

All Articles