Hi,
Thanks for replying.
It’s a custom WP_Query. Currently getting the price from this line (and looping through that for products with variant pricing):
$prices = get_post_meta( get_the_ID(), ‘_price’ );
Here’s the full code:
add_shortcode (‘woo_featured_products’, ‘woo_featured_products’ );
/**
* Create WooCommerce Featured Image Loop Slider
*/
function woo_featured_products() {
ob_start();
?>
<div class=”slick-container-home-page”>
<ul class=”slick-arrows-home-page”>
<li class=”slick-prev-custom”><span>Previous</span></i>
<li class=”slick-next-custom”><span>Next</span></i>
<div class=”home-featured-products”>
<?php
$args = array(
‘post_type’ => array(‘product’, ‘product_variation’),
‘posts_per_page’ => 12,
‘post_parent’ => array(0, 1000),
‘tax_query’ => array(
array(
‘taxonomy’ => ‘product_visibility’,
‘field’ => ‘name’,
‘terms’ => ‘featured’,
),
),
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
$product_thumbnail = get_the_post_thumbnail (get_the_ID(), ‘small’);
// if you leave “true” paramenter in, it will not access price variants
// $price = get_post_meta( get_the_ID(), ‘_price’, true );
// access the prices including variant price array
$prices = get_post_meta( get_the_ID(), ‘_price’ );
// $product_data = get_post_meta( get_the_ID() );
// var_dump($product_data);
?>
<div>
“><?php echo $product_thumbnail; ?>
<div class=”featured-prodcuts-name-price”>
<h4><?php the_title(); ?></h4>
<?php
// We need to keep track of what variable price we are on
$i = 0;
$len = count($prices); // allows us to pinpoint the last variant when we loop through variable prices
foreach ($prices as $price) {
// var_dump($price);
if ($i == 0) {
echo wc_price($price); // echo’s out the first price for variants and only price for simple products
} else if ($i == $len – 1) {
echo ‘ – ‘ . wc_price($price); // this echo’s out the last variant price (highest price) allowing us to display the range of prices for a product
}
$i++;
}
?>
</div>
</div>
<?php endwhile;
} else {
echo __( ‘No products found’ );
}
wp_reset_postdata();
?>
</div>
</div>
<?php
return ob_get_clean();
}