skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    For anyone struggling with the same issue, the solution is to add the following into the WooCommerce section at Stock QTY:

    [MATH({wh1stock[1]},"+",{wh2stock[1]})]
    

    Hope this helps for other users.


  2. Brendon’s solution didn’t work for me, while this did:

    [array_sum(array({wh1stock[1]},{wh2stock[1]}))]
    

    Basically, I’ve used WP All Import’s inline PHP, created an array of values, and summed them.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search