Hi @nvr21,
Is there any chance to sum up a product that has different stocks but the same SKU
Since the product and its stock quantities are across multiple rows, you’d have to write custom code that uses our API to do this. There’s an example here: https://gist.github.com/trey8611/039197cd63c3cb009a3cc3e0b2ea75f8.
Hi @nvr21,
I’m going to mark this as resolved since it’s been a while. Please let us know if you still have questions.
Anyone else with questions, please open a new topic.
Thread Starter
nvr21
(@nvr21)
Hello I just received your email…well I have tried but without luck…
some rows have 2 stocks others 3-6 stocks.
Somehow I need more advice if you can on how to sum all stocks from same product sku.
Many thanks
Thread Starter
nvr21
(@nvr21)
Bump.
I have tried this action hook which works perfectly on the first run and somehow it sums all the rows with the same id instead of overwrite, but on 2nd import, it sums one more time…
Any chance to make it sum on every import?
I mean I need to deactivate overwrite and use append on the stock.
Thanks
function soflyy_add_stock( $product_id, $xml, $update ) {
$new_stock = get_post_meta( $product_id, '_my_new_stock', true );
wc_update_product_stock( $product_id, $new_stock, 'increase' );
}
add_action( 'pmxi_saved_post', 'soflyy_add_stock', 10, 3 );
Hi @nvr21,
I have tried this action hook which works perfectly on the first run and somehow it sums all the rows with the same id instead of overwrite, but on 2nd import, it sums one more time…
You could just remove the code when you don’t need it.
Or, you can use the ‘pmxi_after_xml_import’ hook to add an option in the database that tells you the import has already updated the stocks, then check that option in the “soflyy_add_stock” function before you run your code.