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 ?
WooCommerce provides a Rest API.
You can find the documentation here:
https://woocommerce.github.io/woocommerce-rest-api-docs/
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With