WordPress allowed me to get a better job & better projects in just a Year. I will give you tips, tricks and guide you into WordPress development so you can get more income. Sign up to my 7-day email course!
WooCommerce Stock Management can be easy when you have digital products or products that are by your side, which you store. But what if the products are stored somewhere else, at a wholesaler or some other service? You will need to get the stock level from the service. In this tutorial, we will look into how this can be done.
This tutorial will just show a way on how you can do that but since there are many services and they are all different, I won’t be getting into how to create a complete solution for it but rather show you a guideline on how you can do that.
At the bottom of this tutorial you will also see two videos that I have recorded for this tutorial.
WooCommerce is following the WordPress Standards and thus it uses also the WordPress Plugin API so that you can easily extend or change various parts of WooCommerce.
They have thought about the stock management also!
You can view this method inside the class
WC_Product. With the WordPress Plugin API, we can hook into that filter with a function to return the stock level from our service.
This is an example on how you can hook a function into that. Within that function you can easily return the stock level. This level can be returned from a service.
When you are working with a service, your products will have a unique ID from that service. This ID should be saved somewhere so that we can synchronise the stock level with the appropriate product.
WooCommerce provides hooks to create the fields on various sections. For making the WooCommerce Stock Management easier, we want to hook our field into the inventory section. Here is the hook which we can use:
Inside that hook, we have a function that should create a WooCommerce field. For various field functions, you can view the file at
For the ID we can use the function
woocommerce_wp_text_input( $args ).
You also need a way to save the ID of our Product. We can do that by hooking into:
I have also create two short videos for this also which you can view on my channel or here:
The code that you have seen here and much more (functions, api connection example) can be read in my eBook:
This eBook will help you create your own Shipping method and your own Payment gateway along other smaller but also important parts of WooCommerce.
Web Developer who mainly uses WordPress for projects. Working on various project through Codeable & Toptal. Author of several ebooks at https://leanpub.com/u/igorbenic.
In less than 2 weeks, I have earned $1,800 by working on a custom solution with Easy Digital Downloads without any prior experience. Let me teach you how you can too with various custom solutions.Get the eBook