1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
<?php include( 'wp-load.php' ); // id => sku from com domain // Setup your custom query $args = [ 'post_type' => ['product'/*, 'post', 'page'*/], 'posts_per_page' => 200, 'post_status' => 'publish' ]; function p($a, $d = 1) { echo '<pre>'; var_dump($a); if($d) { die; } } $loop = new WP_Query( $args ); $list = array(); while ( $loop->have_posts() ) : $loop->the_post(); global $post; $product = wc_get_product( $post->ID ); if ( $product->is_type( 'variable' ) ) { //$variations = $product->get_variations(); $variations = $product->get_children(); foreach($variations as $ir => $var) { $variation = new WC_Product_Variation( $var ); $a = 0; if ($variation->get_sale_price() && (int) $variation->get_sale_price() != $variation->get_sale_price()) { $variation->set_sale_price(round($variation->get_sale_price())); $a = 1; } if ($variation->get_regular_price() && (int) $variation->get_regular_price() != $variation->get_regular_price()) { $variation->set_regular_price(round($variation->get_regular_price())); $a = 1; } if ($variation->get_price() && (int) $variation->get_price() != $variation->get_price()) { $variation->set_price(round($variation->get_price())); $a = 1; } if($a) { $variation->save(); } } } elseif( $product->is_type( 'simple' )) { $a = 0; if ($product->get_sale_price() && (int) $product->get_sale_price() != $product->get_sale_price()) { $product->set_sale_price(round($product->get_sale_price())); $a = 1; } if ($product->get_regular_price() && (int) $product->get_regular_price() != $product->get_regular_price()) { $product->set_regular_price(round($product->get_regular_price())); $a = 1; } if ($product->get_price() && (int) $product->get_price() != $product->get_price()) { $product->set_price(round($product->get_price())); $a = 1; } if($a) { $product->save(); } } endwhile; //wp_reset_query(); // Remember to reset echo 'All product loop done<br>'; /*foreach ($list as $key => $value){ echo '"'.$key.'"'.' => '.'"'.$value.'"'.', '; }*/ ?> |