Hi there as the title says, I am trying to import stock quantity from multiple xml files, I am trying to save stock in custom filed and then add code to sum this new filed and existing new and then update new stock value, but it doesnt seem to be working, any advice?

1 Answer 1


I managed to get it working, here is answer:
- when importing update new stock to custom field: _custom_stock_placeholder
- update only this field: _custom_stock_placeholder
- add this code to 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);

  • Actually only worked great the first time it was run, after that it doesn't update. Commented Apr 27, 2019 at 21:52
  • This snippet doesn't effect on first run or second etc. You need to set up your import settings correctly depending what you need. I can help you, contact me with details on slack.
    – dado
    Commented Apr 29, 2019 at 5:59
  • I contacted you, thanks. Commented May 6, 2019 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.