Since I’ve been working a lot lately with synchronising product stock quantities between multiple WooCommerce stores or within a WordPress Multisite network, I can share with you some interesting insights how it is working.
In this tutorial I will not only show you how to get stock quantity in WooCommerce (of a product or a product variation by the way) but we will also display it on the shop page. Like this:
I already have a lot of tutorials about working with REST API on regular WordPress websites, but recently I have updated my Simple WordPress Crossposting plugin to make it compatible with websites hosted on wordpress.com as well.
Unexpectedly there is a huge difference between wordpress.org and wordpress.com APIs, so here is the tutorial where we are about to dive into the example of how create a post with a featured image.
I noticed that when people read my post about uploading a featured image via WordPress REST API, they are also searching how to get a post with its featured image URL.
So I decided to say a couple words about it.
In this tutorial I will show you how to get a product or a product variation object in WooCommerce if you only know its SKU. It is easy-peasy when we get a product object by ID, we just have to use
wc_get_product() function, but we can not pass SKU to that function.
So I am going to show you three different ways how you can obtain a product object from SKU, we are going to do it both WooCommerce-way (with
WP_Product_Query and with
wc_get_product_id_by_sku() function) and WordPress-way (with
Today is another one where I am going to share with you a simple code example how you can add Product image and Product gallery images when creating a product with REST API.
Just in case I mean these things: