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.
I have the same needs. But trying to manage it with the wp all import “orders” option. When importing new orders from wp all import the stock don’t change. But WP all import support gave me this function to add into the settings :
You’ll want to change the import ID from to match the ID of your order import (I’ve set 37 here as an example).
It “almost” works. I mean new orders affect the stocks, but only the main product’s one. My orders are about variation products, and with this tip the variation stock don’t change. I made a short video here :
http://moroccanye.cluster011.ovh.net/stock/DEBUG_ORDER_IMPORT_SOFIA.mov
better than my poor english. If anybody have an idea to improve that code for variations products orders to affect variations products stock… many thanks.
Here is working code:
More at: https://wordpress.stackexchange.com/questions/313782/wp-all-import-update-stock-quantity-from-multiple-xml-files/