Support » Plugin: Import any XML or CSV File to WordPress » Import multiple stock quantity

  • Resolved Drazen

    (@dadodd)


    Hi, is it possible to import stock quantity from 2 different files, so in the wordpress it shows total stock, sum of those 2 files?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @dadodd

    Unfortunately, we don’t have any built-in options for adding the imported stock to the existing stock value. However, you could write some custom code and use custom fields & our API to do it: https://github.com/soflyy/wp-all-import-action-reference/blob/master/all-import/pmxi_saved_post.php. You should be careful doing this, though – it would be easy to accidentally mess up your stock values.

    I am trying something like this: adding stock value to custome field _custom_stock_placeholder and then update original stock with sum of those, but it doesnt seem to be working?

    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);
    
    }
    • This reply was modified 9 months, 3 weeks ago by  Drazen.

    This seems to be working code:

    add_action('pmxi_saved_post', 'post_saved', 10, 1);
    
    function 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);
    
    }
    Plugin Author WP All Import

    (@wpallimport)

    Awesome, thanks for sharing the solution @dadodd !

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Import multiple stock quantity’ is closed to new replies.