I have an XML feed that I use in WP All Import to update my products on my Woocommerce site.
I have two locations where stock is kept in my country - they are called wh1 and wh2 and in the XML feed they are called wh1stock and wh2stock.
I want to have them add up for the qty stock available for a product, e.g. if wh1 has 5 units and wh2 has 5 units the total stock qty should be displayed as 10 units.
I followed this code in my functions.php:
add_action('pmxi_saved_post', 'post_saved', 10, 1);
function post_saved($id) {
$original_stock = get_post_meta($id, '_stock', true);
$new_stock = get_post_meta($id, '_custom_stock_placeholder', true);
$combined_stock= $original_stock + $new_stock;
update_post_meta($id, '_stock', $combined_stock);
}
And created the following custom fields in the WP All Import section: Custom Field Settings and in the Woocommerce section I have the following settings: Woocommerce Settings
However this does not seem to work at all to add up the two stock locations...
Can someone perhaps help me with the correct settings/code please?
Thanks in advance.