In our WooCommerce Multi Inventory plugin the stock information per product is saved in a custom meta field called: woocommerce_multi_inventory_inventories_stock

The data saved is a serialized array consisting of the inventory id <> inventory stock amount.

An example:

array(
    21 => 10,
23 => 20, );

21 is the inventory ID and 10 the stock amount.

When importing this for example you have to use this function:

$product->update_meta_data( 'woocommerce_multi_inventory_inventories_stock', $productInventoriesStock);

Then you also need to make sure the inventory terms are set:

$terms = array_keys( array_filter( $productInventoriesStock) );
wp_set_post_terms($productId, $terms, 'inventories');

And the Total stock is updated (this is the sum of all frontend inventory stocks):

$product->set_stock_quantity($newTotalFrontendStock);

Leave a Reply

Your email address will not be published.