Okay
  Public Ticket #1313658
https://ciaobikeitaly.com/it
Closed

Comments

  •  3
    Pietro started the conversation

    Hi,

    how do i change the variable prices in variable products, to show only the lowest price and a from to before it and when a variation is selected it should disappear.

    I wouldn't ask you, but since there's no snippet that works (while they work for other users) i'm wondering how you guys are making it display and if are you using some custom code.

    Here are some snippets i've used.

    Thanks and regards

    /* 1°
    Disable Variable Product Price Range: 
    */
     
    add_filter( 'woocommerce_variable_sale_price_html', 'my_variation_price_format', 10, 2 );
     
    add_filter( 'woocommerce_variable_price_html', 'my_variation_price_format', 10, 2 );
     
    function my_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( __( '%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( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
     
    if ( $price !== $saleprice ) {
    $price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>';
    }
    return $price;
    }
    /* 2° function iconic_variable_price_format( $price, $product ) {
     
        $prefix = sprintf('%s: ', __('From', 'iconic'));
     
        $min_price_regular = $product->get_variation_regular_price( 'min', true );
        $min_price_sale    = $product->get_variation_sale_price( 'min', true );
        $max_price = $product->get_variation_price( 'max', true );
        $min_price = $product->get_variation_price( 'min', true );
     
        $price = ( $min_price_sale == $min_price_regular ) ?
            wc_price( $min_price_regular ) :
            '<del>' . wc_price( $min_price_regular ) . '</del>' . '<ins>' . wc_price( $min_price_sale ) . '</ins>';
     
        return ( $min_price == $max_price ) ?
            $price :
            sprintf('%s%s', $prefix, $price);
     
    }
     
    add_filter( 'woocommerce_variable_sale_price_html', 'iconic_variable_price_format', 10, 2 );
    add_filter( 'woocommerce_variable_price_html', 'iconic_variable_price_format', 10, 2 );
    3° add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_delivery_date', 10, 2 );
    function wpo_wcpdf_delivery_date ($template_type, $order) {
        $document = wcpdf_get_document( $template_type, $order );
        if ($template_type == 'invoice') {
            ?>
            
                Codice Fiscale:
                <?php $document--->custom_field('cf_in'); ?>
            
            <?php
        }
    }-->
    
  • [deleted] replied

    Hi Pietro,

    After googling for this I have found a code that might work for you:

    // Show mimum variable price
    function show_minimum_variation_price( $price, $product ) {
    $price = '';
    $price .= wc_price( $product->get_price() );
    return $price;
    }

    add_filter( 'woocommerce_variable_price_html', 'show_minimum_variation_price', 10, 2 );
    Based on this article:

    https://www.themelocation.com/how-to-display-minimum-price-from-multiple-variations-in-woocommerce/

    Please let me know if this works for you?

  •  3
    Pietro replied

    Good morning Arlind,

    thanks for your answer.

    I've had to edit a bit the code since another plugin producer was editing already that part, but thanks again! :)

    Regards

  • [deleted] replied

    Hi Pietro,

    Glad to hear that

    One advice for you: It's good to not modify the theme because you can have problems in the future updates. Please be aware as by doing customization if something happens like miss-editing files the responsibility is yours and we wont support you on finding the problem, as we are only guiding you how to get the results you need.

    Will set this ticket as solved from here.

  •  3
    Pietro replied

    Hi Arlind,

    I understand and you're right, but we didn't modify the main theme but just the child.

    As i saw the notices in that file. i thought i've edited it by accident therefore i've replaced it with the original one but it was still giving me those notices.

    Furthermore we've replaced the entire original theme but still was showing those errors.

    Thanks again :)

    Regards