WooCommerce Stock Management using other Services

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.

Filtering the Stock Level

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.

Product Fields

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 woocommerce/includes/admin/wc-meta-box-functions.php.

For the ID we can use the function woocommerce_wp_text_input( $args ).

Saving the Product field

You also need a way to save the ID of our Product. We can do that by hooking into:

Video Tutorial

I have also create two short videos for this also which you can view on my channel or here:

Introduction

Filtering the Stock Level

Learn more about WooCommerce Stock Management

The code that you have seen here and much more (functions, api connection example) can be read in my eBook:

Learn about WooCommerce Stock Management in the eBook on this picture.

This eBook will help you create your own Shipping method and your own Payment gateway along other smaller but also important parts of WooCommerce.

About the Author Igor Benic

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.

follow me on:

Leave a Comment:

WooCommerce Stock Management using other Services

by Igor Benic time to read: 2 min
0