fahadmahmood8/stock-locations-for-woocommerce

Total stock update after WP ALL import

Closed this issue · 4 comments

Problem with Total Stock update after WP All Import. We can setup locations stock count, but we never get total stock count. Only after hitting update button we can get total stock count.

Additional warehouses are not active when importing with "wp all import". How do I turn on these warehouses during import? When manually activating additional warehouses in the "products" tab, and then starting the import of only states, the general state is correct.

On WP All Import process you can use code like this:

add_action('pmxi_saved_post', 'post_saved', 10, 1);

function post_saved($post_id) {

$post_manufacturer_stock = get_post_meta($post_id, '_stock_at_32252', true);
if(!$post_manufacturer_stock){
    $post_manufacturer_stock = 0;
}
$post_riga_stock = get_post_meta($post_id, '_stock_at_32251', true);
if(!$post_riga_stock){
    $post_riga_stock = 0;
}
$post_total_stock = $post_manufacturer_stock + $post_riga_stock;
$stock = get_post_meta($post_id, '_stock', true);
if($stock < $post_total_stock){
   update_post_meta($post_id, '_stock', $post_total_stock);
}

wc_delete_product_transients( $post_id );
$arg = array(
    'ID'            => $post_id
);
wp_update_post( $arg );

}

function wpai_wp_all_import_variation_imported( $variation_id ){

wc_delete_product_transients( $variation_id );
$arg = array(
    'ID'            => $variation_id
);
wp_update_post( $arg );

}

add_action( 'pmxi_product_variation_saved', 'wpai_wp_all_import_variation_imported', 10, 1 );

This is for the total product count after WP ALL import. We use 2 stocks, one stock is in place, another stock is the manufacturer. Code check if both stocks are the same as total, if not, do total stock count update based on both locations. In default only after you hit an update button on the product, the total stock is correct.

Sorry to interrupt but just want to mention here about CRONS /wp-admin/admin.php?page=slw-settings&tab=crons
You may run the cron url manually as well, it will update the stock levels for all product items.