Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require('../../../wp-load.php');
- global $wpdb;
- $file = 'updatequantity.csv';
- $handle = fopen($file, "r");
- fgetcsv($handle,1000,",");// remove first row/header file must have a header to not lose the first row of data
- while(($fileop = fgetcsv($handle,1000,",")) !==false)
- {
- // gets the correct columns
- $sku = $fileop[0];
- $quantity = $fileop[1];
- // gets the product id so we can later update where id =...
- $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku ) );
- if ($product_id != '') {
- // Update meta
- update_post_meta( $product_id, '_stock', $quantity );
- // Clear total stock transient
- delete_transient( 'wc_product_total_stock_' . $product_id );
- }
- else{
- echo "No Id Found for SKU: $sku</br>";
- }
- }
- echo "Stock Quantity Updated</br>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement