Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #861289

    THIS IS NOT A SUPPORT REQUEST, IT’S JUST THE TIP BRO

    When you have variable products that have a large difference in price range, you may not want to display the full price range. Why? Sometimes seeing that larger price up front can scare a customer off, especially when you’re selling a service. Instead, you might want to display something like, “Starting at $15”. Here is some code that will adjust the price HTML code in WooCommerce. Note, this will change it both on the listing and the product page (if you’re using the standard layout and not the Advanced Layout option).

    Here is an example…
    Change Product Price Listing

    Place in your child theme’s functions.php file and adjust as needed.

    // Change price format from range to "Starting at"
    function variable_price_format( $price, $product ) {
    
        $prefix = sprintf('%s &nbsp;', __('<span style="font-weight:normal !important; color:#858585 !important; font-size:13px !important;">STARTING AT</span>'));
    
        $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 ) :
            wc_price( $min_price_sale );
    
        return ( $min_price == $max_price ) ?
            $price :
            sprintf('%s%s', $prefix, $price);
    
    }
    
    add_filter( 'woocommerce_variable_sale_price_html', 'variable_price_format', 10, 2 );
    add_filter( 'woocommerce_variable_price_html', 'variable_price_format', 10, 2 );
    #861503

    Hey Kahil,

    Thanks again for sharing :-)

    Best regards,
    Rikard

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.