Display Average Price After the Regular/Wholesale Price (WooCommerce) by Calculation


I have products which are in wholesale/bundles and comes under the 6-9 pieces per product. Now I want to display two prices, first will be the wholesale price which will be by default regular price of the product and second will be the per pieces/average price for each product. I have figured out the first price part but for the average price, I have added a custom filed named as “pieces” in the backend and given the values in products.

I am using following code to calculate and display the Average price on the sales/category page and product page.

function average_price(){
    $averageprice= "$wholesaleprice / $wholesalepieces";

<p class="<?php echo esc_attr( add_action( 'woocommerce_product_price_class', 'average_price' ) ); ?>"><?php echo "Average Price : ", get_woocommerce_currency_symbol(). $averageprice; ?></p>

I am editing in price.php under woocommerce plugin.

Please tell me what I am doing wrong? If you want additional info then I will be happy to provide it.

, , , rt5277 4 years 2020-03-23T12:51:44-05:00 0 Answers 116 views 0

Leave an answer