Created
October 3, 2018 16:55
-
-
Save eto4detak/86cdd7c57e4d26419207569cf7b714d7 to your computer and use it in GitHub Desktop.
wp php woo update price
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 | |
function divie_all_products_woo_edit(){ | |
$euro_rate = get_option('divie_euro_rate') ? get_option('divie_euro_rate') : ''; | |
$euro_rate = floatval($euro_rate); | |
if(!empty($euro_rate) && is_float($euro_rate) && $euro_rate > 0){ | |
$args = array( | |
'post_type' => array( 'product',), | |
'posts_per_page' => -1, | |
); | |
$the_query = new WP_Query( $args ); | |
global $post; | |
if ( $the_query->have_posts() ) : | |
while ( $the_query->have_posts() ) : $the_query->the_post(); | |
$euro = get_post_meta( $post->ID, '_euro_rate', true ); | |
if(!empty($euro)){ | |
$euro = floatval($euro); | |
// $price = get_post_meta($post->ID, '_regular_price'); | |
$price = round( $euro * $euro_rate, 2 ); | |
$price = (float)$price; | |
update_post_meta( $post->ID, '_regular_price', $price ); | |
update_post_meta($post->ID, '_price', $price ); | |
} | |
endwhile; | |
endif; | |
wp_reset_query(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment