Advertisement
bowenac

Untitled

Apr 30th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. <?php
  2. require('../../../wp-load.php');
  3. global $wpdb;
  4.  
  5. $file = 'updatequantity.csv';
  6. $handle = fopen($file, "r");
  7. fgetcsv($handle,1000,",");// remove first row/header file must have a header to not lose the first row of data
  8.  
  9. while(($fileop = fgetcsv($handle,1000,",")) !==false)
  10. {  
  11. // gets the correct columns
  12. $sku = $fileop[0];
  13. $quantity = $fileop[1];
  14. // gets the product id so we can later update where id =...
  15. $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku ) );
  16.  
  17. if ($product_id != '') {
  18.     // Update meta
  19.     update_post_meta( $product_id, '_stock', $quantity );
  20.     // Clear total stock transient
  21.     delete_transient( 'wc_product_total_stock_' . $product_id );
  22. }
  23. else{
  24.     echo "No Id Found for SKU: $sku</br>";
  25. }
  26. }
  27. echo "Stock Quantity Updated</br>";
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement