I'm currently using WP All Import to import data (specifically stock quantity). When I import the stock quantity it overwrites my current data, and what I would like for it to do is to update data. Lets say WooCommerce had 5 and my CSV sheet has 5, I would like those two values to add (equaling 10).
I did email WP All Import support to provide some indication on what was required to get the above to work, and here is their:
"If you are good with code you can make that work using a custom post-processing function. Simply import your stock value into a placeholder custom field. Then through a function attached to the "pmxi_saved_post" action you would access both the actual stock custom field and the placeholder one. Add the values of both and update the final stock. http://www.wpallimport.com/documentation/developers/action-reference/";
I have no clue where to start. Any input would be appreciated it.
The solution is right front of your.
Approach:
Add the below function into the theme's functions.php file
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);
}
Add another custom field from dashboard or while using WP ALL IMPORT say '_custom_stock_placeholder' to the products.
While using WP ALL IMPORT assign the new stock value to the above mentioned custom field rather than original '_stock' field.
Rest the function will calculate and do the needful for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With