Чтобы обновить цену варианта, пожалуйста, используйте цикл WP_Query
,
Вставьте приведенный ниже код в текущий файл активной темы functions.php.
$query = array(
'post_status' => 'publish',
'post_type' => array('product', 'product_variation'),
'posts_per_page' => -1
);
$the_query = new WP_Query($query);
//product loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
global $post;
$product = wc_get_product( $post->ID ); // An instance of the WC_Product object
// Only for variable products
if( $product->is_type('variable') ){
foreach( $product->get_available_variations() as $variation_values ){
$variation_id = $variation_values['variation_id']; // variation id
$regular_price = get_post_meta( $variation_id, '_regular_price', true);
$regular_price = $regular_price * 6;
// Updating active price and regular price
update_post_meta( $variation_id, '_regular_price', $regular_price );
update_post_meta( $variation_id, '_price', $regular_price );
wc_delete_product_transients( $variation_id ); // Clear/refresh the variation cache
}
// Clear/refresh the variable product cache
wc_delete_product_transients( $post->ID );
}
}
wp_reset_postdata();
}
Надеюсь, тебе это поможет.