Display the average cost of products on a Woocommerce page

Viewed 20

Displayed products by category, you need to display their average cost? could only get the cost itself.

                'post_type' => 'product',
                'posts_per_page' => -1,
                'post_status'   => 'publish',
                'tax_query' => array(
                    array(
                        'taxonomy' => 'product_cat',
                        'field' => 'slug',
                        'terms' => 'sale',
                    )
                ),
            );
            $sale = new WP_Query($saleArgs); ?>
            <?php if ($sale->have_posts()) : ?>
                <?php while ($sale->have_posts()) : $sale->the_post(); ?>
                    <?php wc_get_template_part('content', 'product'); ?>

                <?php endwhile; ?>
                <?php wp_reset_postdata(); ?>
            <?php endif; ?>
    <?php $sale = get_post_meta(get_the_ID(), '_price', true);
                    echo $salee  ?>
0 Answers
Related