• Resolved corestudio

    (@corestudio)


    Hello,

    When I have a product with more than one attribute (size or color, for example), the price on the main product page shows the range containing the lower price and the higher price. I’d like to know if it’s possible to show only one price (the lower one, for example) instead of the range.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @corestudio

    Thanks for reaching out!

    I understand that you want to display the lowest price only for your variable products.

    I did some research and found this code snippet that worked on my site:

    // Show only lowest prices in WooCommerce variable products
    
    add_filter( 'woocommerce_variable_sale_price_html', 'wpglorify_variation_price_format', 10, 2 );
    add_filter( 'woocommerce_variable_price_html', 'wpglorify_variation_price_format', 10, 2 );
     
    function wpglorify_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 . $product->get_price_suffix() . '</del> <ins>' . $price . $product->get_price_suffix() . '</ins>';
    }
    return $price;
    }

    Output:

    Image Link: https://snipboard.io/ZLgbU4.jpg

    The code came from this link: https://wpglorify.com/show-lowest-price-woocommerce-variable-products/

    Hope this helps!

    Thread Starter corestudio

    (@corestudio)

    It worked for me, thank you very much!

    • This reply was modified 3 years, 6 months ago by corestudio.

    I’m glad we were able to help, @corestudio! If you have a few minutes, we’d love if you could leave us a review: https://ww.wp.xz.cn/support/plugin/woocommerce/reviews/

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Multiple attributes prices’ is closed to new replies.