How do I output the Minimum and Maximum prices in the Category Woocommerce?

Please tell me how to output the woocommerce Minimum and Maximum prices of the items in the current Category. Just 2 numbers — the price of the cheapest product of the category and the most expensive.
June 10th 19 at 16:04
1 answer
June 10th 19 at 16:06
/**
 * Gets the value ekstremalne price in the product category
 * @param $term_id - id of the product category
 * 
 * @return mixed
*/
 wpp_get_extremes_price_in_product_cat function( $term_id ) {

 global $wpdb;
 $sql = "
 SELECT MIN( meta_value ) as min_price , MAX( meta_value ) as max_price
 FROM {$wpdb->posts} 
 INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)
 INNER JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id) 
 WHERE 
 ( {$wpdb->term_relationships}.term_taxonomy_id IN (%d) ) 
 AND {$wpdb->posts}.post_type = 'product' 
 AND {$wpdb->posts}.post_status = 'publish' 
 AND {$wpdb->postmeta}.meta_key = '_price'
";

 $result = $wpdb->get_results( $wpdb->prepare( $sql, $term_id ) );

 return $result[ 0 ];

 }
Thank you!
I put it in functions.php?
What to add to bring the numbers on the page? - Harrison_Anderson32 commented on June 10th 19 at 16:09
Here is where you climb? You don't even know the basics of the language.
This is a function, insert anywhere, and function.php
where necessary the withdrawal
$extremes = wpp_get_extremes_price_in_product_cat( 55 ); // 55 - id of the product category
printf('the minimum price is %s, maximum price %s',$extremes->min_price ,$extremes->max_price );
- Earlene_Stehr34 commented on June 10th 19 at 16:12
everything's fine prints, you really helped me, thank you!
Just a small clarification - how to make that when you change currency on the website these figures have also been restated? - Harrison_Anderson32 commented on June 10th 19 at 16:15
,
This is not a small clarification. This radically changes the query to the database.
And since I don't know what you use for multicurrency store and how it stores values and not say.
My function works with standard WooCommerce - Earlene_Stehr34 commented on June 10th 19 at 16:18
I have is WooCommerce Currency Switcher /currency-switcher.com/
So I have displays the currency code (if you change the currency it updates the value).
<?php
 $currency_code = get_woocommerce_currency();
 echo $currency_code;
?>
- Harrison_Anderson32 commented on June 10th 19 at 16:21
is not a change of currency and the receipt currency.
and to understand how it is arranged you there, no time. - Earlene_Stehr34 commented on June 10th 19 at 16:24
in any case, thank you! - Harrison_Anderson32 commented on June 10th 19 at 16:27

Find more questions by tags WooCommerceWordPress