Last active
June 27, 2019 16:15
-
-
Save eto4detak/49291adbbd7e2c09eb50cc62979e6cf2 to your computer and use it in GitHub Desktop.
woo php update-product
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach ($product_list as $data) { | |
// код 1С; артикул (ориентироватья ненадо); 0 нет в наличии > 0 в наличии; цена | |
$sku = trim($data[0]); // код 1С | |
$sku = $data[1]; // артикул (ориентироватья ненадо) | |
$quantity = $data[2]; // нет в наличии > 0 в наличии | |
$price = $data[3]; // цена | |
$found = false; | |
//$code_1s_utf = iconv('windows-1251', 'utf-8', $code_1s); | |
$product_id = wc_get_product_id_by_sku($sku); | |
// $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 ) { | |
$wc_product = new WC_Product( $product_id ); | |
if ($wc_product) { | |
$price = str_replace(' ', '', $price); | |
$price = str_replace(',', '.', $price); | |
$price = floatval($price); | |
update_post_meta($product_id, '_regular_price', $price); | |
update_post_meta($product_id, '_price', $price); | |
if ($quantity > 0) { | |
update_post_meta($product_id, '_stock_status', 'instock'); | |
} else { | |
update_post_meta($product_id, '_stock_status', 'outofstock'); | |
} | |
if($code_1s == 'УТ000031432') { | |
//var_dump($price); | |
} | |
$found = true; | |
} | |
} | |
if(!$found) { | |
//$not_found[] = $code_1s; | |
fputcsv($fp, array($code_1s)); | |
} else { | |
fputcsv($fp_found_file, array($code_1s)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment