Woocommerce округлить цены

<?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.'"'.', ';
}*/
?>

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *