• I have successfully allocated Wp All Import to import correct stock numbers to locations, however after import, the stock total for the product remains at 0 unless I manually update that product.
    I cannot do this manually for thousands of products each import.
    I have checked your other support topics and added your snippet code to my theme functions.php.
    See screenshots here:
    https://www.dropbox.com/sh/jjyondb4t9l0vd3/AACqewLjN5idzvncxjSCX10Na?dl=0

    Not sure what I’m missing to get the actual stock level to update..

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hi @rivalink

    You need to update the product main stock too in the meta _stock.

    Thread Starter rivalink

    (@rivalink)

    @alexmigf how do I do that?
    What fields would I enter?

    Plugin Contributor alexmigf

    (@alexmigf)

    @rivalink you need to update that meta when updating the locations, the same way.

    Thread Starter rivalink

    (@rivalink)

    @alexmigf did you check screenshots in dropbox link. The meta _stock is already set to update in the import settings..

    Plugin Contributor alexmigf

    (@alexmigf)

    Hi @rivalink

    Sorry, I didn’t check that.

    In that case I don’t see any reason for that, and that’s an issue from the WP All Import itself (settings maybe). If you want me to take a look please email me.

    @deshoon1 @rivalink If you got the solution for this im eager to hear it. Im fighting with exact same problem at the moment

    Hi,

    This is an example for updating existing products. Of course, you can do this for new products as well, but this time I will explain how to update existing ones.

    In order to have this work out, your products need to have all those locations already assigned. You can also assign locations to products using WP All import, but that is a different topic.

    Lets begin now.

    In WP All import, when you initiate an import, you will find an option called “Function editor”. There you can add your PHP code snippet.

    But before you do that, you need to identify your custom fields for all your locations you are using for your stock.

    Usually those fields are looking something like this: _stock_at_1234

    This number part (1234) you will find under WooCommerce >> SLW settings. Those numbers are actually your stock location IDs. So they are different from website to website.

    Lets pretend for this example that my stock location IDs are: 1234 and 5678, so I am using 2 stock locations.

    So, now when we have all we need, this is the code snippet we have to implement in WP all import:

    <?php
    add_action( 'pmxi_saved_post', 'my_fix_stock', 10, 1 );
    
    function my_fix_stock( $id ) {
    	$product = wc_get_product( $id );
    	if ( ! $product ) return;
    	
    	$stock1 = $product->get_meta( '_stock_at_1234', true );
    	$stock2 = $product->get_meta( '_stock_at_5678', true );
        
    	
    	if ( empty( $stock1 ) ) $stock1 = 0;
    	if ( empty( $stock2 ) ) $stock2 = 0;
    	
    	$product->set_stock_quantity( $stock1 + $stock2 );
    	$product->save();
    }
    ?>

    You change these dummy values with your real ones, paste the snippet and hit save. Also, adjust this code for all your locations accordingly.

    Upper, in the inventory tab, do not put any values in your stock quantity field, set manage stock to on and stock status has to be set automatically.

    Those are all actions you need to take in that step. In the next step, you need to tell WP all import how to run the update, how to match the records.

    So, records in your file will be matched with products on your site based on SKUs, product IDs, or whatever you are using as a special custom field (EANs, MPNs…)

    You are updating existing products, so you set that checkbox and then you choose which data to update.

    For this, you are using only custom fields and you are setting the option called: update only these custom fields and to leave the rest alone.

    Custom fields are:

    _stock_at_1234
    _stock_at_5678
    _stock
    _manage_stock

    Again, do not forget to change dummy numbers with your real values.

    Save the settings, go to the next step and run the import.

    Hopefully this helps.

    • This reply was modified 3 years, 9 months ago by Elliot.
    • This reply was modified 3 years, 9 months ago by Elliot.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘HOW TO UPDATE PRODUCT AFTER WP ALL IMPORT’ is closed to new replies.