• Resolved nvr21

    (@nvr21)


    Hello,
    Is there any chance to sum up a product that has different stocks but the same SKU

    ex:
    SKU name stock
    12 product-test 44
    12 product-test 32
    12 product-test 12
    12 product-test 6

    so the output will be: 12 product-test 94
    also, some products have different stocks one of them 2 others 5-6

    Thanks and waiting for your answerer

    • This topic was modified 4 years, 1 month ago by nvr21.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author WP All Import

    (@wpallimport)

    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.

    Plugin Author WP All Import

    (@wpallimport)

    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 );
    Plugin Author WP All Import

    (@wpallimport)

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Merge multiple stocks same sku’ is closed to new replies.