New Landing How can we help? Themeforest Theme Support Uplift Is it possible to display prices "From"?

Viewing 14 posts - 1 through 14 (of 14 total)
  • Posted in: Uplift
  • #280734
    nosuchagency
    Member
    Post count: 226

    Hello.

    Currently the products in our shop shows price ranges (like: 8.349 DKK–10.289 DKK).
    Is it possible to show prices from XXX.

    Like this: From 8.349 DKK

    Thank you.

    SørenJ.

    Attachments:
    You must be logged in to view attached files.
    #280740
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    Yes, add this to your child theme’s functions.php file

    
    // Use WC 2.0 variable price format
    add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 );
    add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 );
    function wc_wc20_variation_price_format( $price, $product ) {
    $min_price = $product->get_variation_price( 'min', true );
    $max_price = $product->get_variation_price( 'max', true );
    if ($min_price != $max_price){
    $price = sprintf( __( 'From %1$s', 'woocommerce' ), wc_price( $min_price ) );
    return $price;
    } else {
    $price = sprintf( __( '%1$s', 'woocommerce' ), wc_price( $min_price ) );
    return $price;
    }
    }

    – Kyle

    #280762
    nosuchagency
    Member
    Post count: 226

    Awesomeness!

    Thanks a lot – You can close this ticket :o)

    #280766
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    No problem! 🙂

    #280873
    nosuchagency
    Member
    Post count: 226

    Hi Kyle.

    The code provided had an unintentional side effect.
    All Price Display Suffix has now disappeared from the site (and that’s bad!).

    Can you adjust the code so this doesn’t happen?
    Please advice.

    Attachments:
    You must be logged in to view attached files.
    #280877
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    Try this code instead of previous:

    /**		 * Use WC 2.0 variable price format, now include sale price strikeout		 *		 * @param  string $price		 * @param  object $product		 * @return string		 */		function wc_wc20_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;		}		add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 );		add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 );

    – Kyle

    #280881
    nosuchagency
    Member
    Post count: 226

    Hi Kyle.

    No, that didn’t work…
    Now the original issue (Prices from XX) is back :o(

    Attachments:
    You must be logged in to view attached files.
    #280891
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    Try:

    // Use WC 2.0 variable price format
    add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 );
    add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 );
    function wc_wc20_variation_price_format( $price, $product ) {
    $min_price = $product->get_variation_price( 'min', true );
    $max_price = $product->get_variation_price( 'max', true );
    if ($min_price != $max_price){
    $price = sprintf( __( 'From %1$s', 'woocommerce' ), wc_price( $min_price ) );
    return $price;
    } else {
    $price = sprintf( __( '%1$s', 'woocommerce' ), wc_price( $min_price ) );
    return $price . 'inkl. moms'; 
    }
    }

    – Kyle

    #280900
    nosuchagency
    Member
    Post count: 226

    Hi Kyle.

    Well, now it get’s tricky.
    Seems like some of the products has the “including VAT” suffix (in Danish: Inkl. moms), but others have no suffix??
    You’re welcome to log in on the site, using the credentials provided, an snoop around.

    See screenshot attached.

    Best regards.

    Attachments:
    You must be logged in to view attached files.
    #280904
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    Are they all variable products?

    – Kyle

    #280916
    nosuchagency
    Member
    Post count: 226

    Hi Kyle.

    We have both products with variation and without.
    It looks like all products without variations are the ones missing the suffix…

    SørenJ.

    #280919
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    Did they have suffix before you added the code?

    – Kyle

    #280920
    nosuchagency
    Member
    Post count: 226

    Yes :o)

    #280937
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    Hmm ok not sure about that, I grabbed the code from here https://gist.github.com/kloon/8981075

    You’re best contacting woocommerce support and asking them how to use the old price format along with keeping the price suffix

    – Kyle

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.