I’m using the ACF post object field to display multiple Woocommerce products as post type items. However, I’m trying to only display the prices of these selected products as a min/max price range (eg. $21.95 – $58.50).
Here is the code I’m using for the loop but it just shows every price. Is there a way to just show the lowest and highest price as a price range?
<?php
$linked_products = get_field('linked_products');
if( $linked_products ): ?>
<?php foreach( $linked_products as $post ):
setup_postdata($post); ?>
<?php $product = wc_get_product( $post ); $prices = $product->get_price_html(); echo $prices; ?>
<?php endforeach; ?>
<?php
wp_reset_postdata(); ?>
<?php endif; ?>
2
Answers
Maybe you could set php variables and store lowest and highest price in those variables
Try the following code. It displays the prices range as lowest price to highest price: