Hi @dadodd
Unfortunately, we don’t have any built-in options for adding the imported stock to the existing stock value. However, you could write some custom code and use custom fields & our API to do it: https://github.com/soflyy/wp-all-import-action-reference/blob/master/all-import/pmxi_saved_post.php. You should be careful doing this, though – it would be easy to accidentally mess up your stock values.
Thread Starter
Drazen
(@dadodd)
I am trying something like this: adding stock value to custome field _custom_stock_placeholder and then update original stock with sum of those, but it doesnt seem to be working?
add_action('pmxi_saved_post', 'wdm_post_saved', 10, 1);
function wdm_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);
}
-
This reply was modified 7 years, 8 months ago by
Drazen.
Thread Starter
Drazen
(@dadodd)
This seems to be working code:
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);
}
Awesome, thanks for sharing the solution @dadodd !