Digital experiences for all disciplines
New Landing › How can we help? › Themeforest Theme Support › Uplift › Is it possible to display prices "From"?
New Landing › How can we help? › Themeforest Theme Support › Uplift › Is it possible to display prices "From"?
- This topic has 13 replies, 2 voices, and was last updated 8 years by Kyle – SUPPORT.
-
Posted in: Uplift
-
July 12, 2016 at 1:17 pm #280734
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.July 12, 2016 at 1:33 pm #280740Yes, 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
July 12, 2016 at 2:44 pm #280762Awesomeness!
Thanks a lot – You can close this ticket :o)
July 12, 2016 at 2:53 pm #280766No problem! 🙂
July 13, 2016 at 8:44 am #280873Hi 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.July 13, 2016 at 8:52 am #280877Try 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
July 13, 2016 at 9:06 am #280881Hi 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.July 13, 2016 at 9:21 am #280891Try:
// 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
July 13, 2016 at 9:44 am #280900Hi 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.July 13, 2016 at 9:50 am #280904Are they all variable products?
– Kyle
July 13, 2016 at 10:09 am #280916Hi Kyle.
We have both products with variation and without.
It looks like all products without variations are the ones missing the suffix…SørenJ.
July 13, 2016 at 10:10 am #280919Did they have suffix before you added the code?
– Kyle
July 13, 2016 at 10:11 am #280920Yes :o)
July 13, 2016 at 10:26 am #280937Hmm 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
-
Posted in: Uplift
You must be logged in to reply to this topic.