WooCommerce Measurement Price Calc - replace price range by min price

Hopefully the title is fairly self explanatory! I'm using Measurement Price Calculator (MPC) in WooCommerce here. I have added the tweak in my functions.php to alter the price display on variable products so that it hides the from - to price range and just shows "from {lowest price}" . I believe this is a fairly common tweak users make in WooCommerce but I'll include the code I used below for good measure as I hope it might be adaptable for MPC also.

My issue is that when using the Pricing Tables feature of MPC, it goes back to showing the price range of the table, e.g. "€0.86 - €0.98 / sq m" . My tweak does not catch this and I have contacted the developers Skyverge, who couldn't give me a fix but did point me to "wc_measurement_price_calculator_get_price_html" filter.

Has anyone here managed to this or similar when using MPC or can anyone suggest a use for the filter suggested by Skyverge?

The code I'm using for variable products is as below:

// Hide Price Range on Variable Products

add_filter( 'woocommerce_variable_sale_price_html', 'variation_price_format', 10, 2 );

add_filter( 'woocommerce_variable_price_html', 'variation_price_format', 10, 2 );

function variation_price_format( $price, $product ) {
    // Main Price
    $prices = array( $product->get_variation_price( 'min', true ), 
    $product->get_variation_price( 'max', true ) );
    $price = $prices[0] !== $prices[1] ? sprintf( __( 'from %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );

    // Sale Price
    $prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
    sort( $prices );
    $saleprice = $prices[0] !== $prices[1] ? sprintf( __( 'from %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );

    if ( $price !== $saleprice ) {
        $price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>';
    }

    return $price;
}

Solutions

Without any guaranty, try this:

add_filter('wc_measurement_price_calculator_get_price_html', 'm_p_caculator_variable_product_prices', 10, 1 );
function m_p_caculator_variable_product_prices( $price_html ) {
    if( ! $product->is_type('variable') ) return $price_html; // Only variable products
    // Main Price
    $prices = array(  $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
    $price_html = $prices[0] !== $prices[1] ? sprintf( __( 'from %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );

    // Sale Price
    $prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
    sort( $prices );
    $sale_price = $prices[0] !== $prices[1] ? sprintf( __( 'from %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );

    if ( $price_html !== $saleprice ) {
        $price_html = '<del>' . $saleprice . '</del> <ins>' . $price_html . '</ins>';
    }

    return $price_html;
}

Code goes in function.php file of your active child theme (or active theme). Untested.

Similar questions

Measurement units conversion based on country in Woocommerce product page
I have a woocommerce site set to use Kg and cm as dimension units in the backend settings. The site mainly sells to Europe so no worries. Now I have to sell to US market to and I am being asked to configure the site so that when users in the US-Client group login they see Imperial measurements either as well as or instead of Metric units. Is there ...
How to set a non existing dimensions measurement unit in Woocommerce 3
In WooCommerce I would like to change cm to ft my products display in height, width and length, You can see the products with their title below:
wordpress - "user-profile.min.js" and "password-strength-meter.min.js" blocked via ssl - https
As the Title describes: I have two Wordpress JS´s that where blocked beacause it´s not loading from https. But Why? I´m not sure if thats right but this is already set: define('FORCE_SSL_ADMIN', true); My Server try to load it from: http://examples.tld/wordpress/wp-admin/user-profile-min.js But it has to be from https: https://examples.tld/wordpres...
why does twenty eleven theme mix up the css measurement units?
I'm wondering why does WordPress's default theme mix up the css measurement units? For example: Wouldn't be easier to understand and to work if all them were pixel based? Thanks
Share posts url with prefix for GA measurement
We have a Wordpress site with different permalink structures and we need a way to share different post links (via email newsletter) so we can measure via GA how many visits the site receives from mail users. We were thinking on adding a prefix like newsletter but we are open to other solutions. Thanks in advance!
Replace Woocommerce product variable price range from custom field values
I want to use a custom field to add price for vendors in variable products. So, I am using the following code to get the maximum and minimum price of custom field of variable product, but it return nothing. Please help me to find how can get the price from custom field for variable products.

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy .