<?php
require_once(‘../wp-load.php’);
global $wpdb;
// $product_ids=array(18744);
// foreach($product_ids as $ak=>$product_id){
// $product = wc_get_product( $product_id );
// $product->set_name(‘Hello 2’);
// $product->set_stock_quantity(‘9999’);
// $product->set_slug(‘test-‘.$product_id);
// $product->set_price(’50’);
// $product->set_regular_price(‘5’);
// //$product->set_sale_price(‘4’);
// //$product->save();
// }
$row = 0;
if (($handle = fopen(“test.csv”, “r”)) !== FALSE) {
while (($data = fgetcsv($handle, 1000, “,”)) !== FALSE) {
$num = count($data);
echo “<p> $num fields in line $row: <br /></p>\n”;
$row++;
for ($c=0; $c < $num; $c++) {
if($row == 1) continue;
$product_id= $data[0];
$product = wc_get_product( $product_id );
//$product->set_name($data[1]);
if( $product ){
$product->set_price($data[2]);
$product->save();
}else{
}
}
}
fclose($handle);
}
/*$allProducts = wc_get_products([
‘posts_per_page’ => -1,
]);
foreach($allProducts as $product){
$productSlug = $product->get_slug();
$productTitle = str_replace(‘-‘, ‘ ‘, $productSlug);
$productTitle = preg_replace(“/[^A-Za-z ]+/”, “”, $productTitle);
$productTitle = implode(‘ ‘, array_map(‘ucfirst’, explode(‘ ‘, $productTitle)));
wp_update_post([
‘ID’ => $product->get_id(),
‘post_title’ => $productTitle
]);
$productTitle;
}
*/
$args = array(
‘post_type’ => ‘product’,
‘posts_per_page’ => 10,
//’product_cat’ => ‘hoodies’
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
//echo ‘<br /><a href=”‘.get_permalink().'”>’ . woocommerce_get_product_thumbnail().’ ‘.get_the_title().'</a>’;
endwhile;
wp_reset_query();
?>