Woocommerce: Show variable price instead of "From" price

I have been searching for this for quite a while now and i can't find any solutions.

I am looking for a way to display the products variation prices inside the "From:" price field , in order to have only 1 price shown on the product page.

I have tried this:

function woocommerce_template_single_price() {
global $product;
if ( ! $product->is_type('variable') ) { 
    woocommerce_get_template( 'single-product/price.php' );
}}

But it doesn't work for me, The price should change dynamicaly when a different product variation is selected. Any ideas?

Solutions

add_action( 'woocommerce_before_single_product', 'check_if_variable_first' );
function check_if_variable_first(){
    if ( is_product() ) {
        global $post;
        $product = wc_get_product( $post->ID );
        if ( $product->is_type( 'variable' ) ) {
            // removing the price of variable products
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );

// Change location of
add_action( 'woocommerce_single_product_summary', 'custom_wc_template_single_price', 10 );
function custom_wc_template_single_price(){
    global $product;

// Variable product only
if($product->is_type('variable')):

    // 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 && $product->is_on_sale() ) {
        $price = '<del>' . $saleprice . $product->get_price_suffix() . '</del> <ins>' . $price . $product->get_price_suffix() . '</ins>';
    }

    ?>
    <style>
        div.woocommerce-variation-price,
        div.woocommerce-variation-availability,
        div.hidden-variable-price {
            height: 0px !important;
            overflow:hidden;
            position:relative;
            line-height: 0px !important;
            font-size: 0% !important;
        }
    </style>
    <script>
    jQuery(document).ready(function($) {
        $('select').blur( function(){
            if( '' != $('input.variation_id').val() ){
                $('p.price').html($('div.woocommerce-variation-price > span.price').html()).append('<p class="availability">'+$('div.woocommerce-variation-availability').html()+'</p>');
                console.log($('input.variation_id').val());
            } else {
                $('p.price').html($('div.hidden-variable-price').html());
                if($('p.availability'))
                    $('p.availability').remove();
                console.log('NULL');
            }
        });
    });
    </script>
    <?php

    echo '<p class="price">'.$price.'</p>
    <div class="hidden-variable-price" >'.$price.'</div>';

endif;
}

        }
    }
}

Similar questions

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 WooCommerc...
How to exclude a variable price from the WooCommerce price filter?
I need to remove one specific variable price from the price filter and for the WooCommerce order by price. I have 4 variable product, and I don't want to show one variable attribute that contains the price $495 for all products in the price filter. I just want to hide this specific attribute so it will not be counted in the price filter as well as ...
WooCommerce Cart - Dynamic Price variable pass into custom price hook
I am getting the dynamic custom price in a variable that I want to pass to the hooked function in woocommerce_before_calculate_totals hook in cart. But it isn't working. This is my code: How can I achieve this? Thanks
Variable product price not showing in listing and details page WooCommerce Price Based on Country
When the product is listed in Product listing page or Product details page, The price not showing.When I click on any variation like color,then only the product price is displayed.If I deactivate the plug-in its all works good. Note: I am using All the products are variable products(color). I surfed on net for this and found something like this *Wo...
Replace the Variable Price range by the chosen variation price in WooCommerce 3
On WooCommerce I would like to change the Variable single product page layout. Because, when you have an variable product you get this wired price rage ( below product title ) in the Variable Product page and it shows in the shop page as well. For me the standard way is to show the lowest price of the product in the shop as well as product page and...
Replace variable products price range with "From:" + lowest price in WooCommerce
In WooCommerce when a Variable product has variations with different prices it displays a price range with 2 amounts: For example 89.00 - 109.00. I'd like to change it, displaying only "From: " and the lowest price like for example From: 89.00 (removing the Max price). ("Fra: " means from in my language, just to clarify). Here is the code that I ha...

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 .