Tagged: x
-
AuthorPosts
-
October 16, 2016 at 10:00 am #1218211
Geert SParticipantHi X-ers,
Recently I was given the brilliant code below to change variable prices from xxx.xx-yyy.yy to From XXX.XX -I’v echanged the ‘From:’ to ‘Starts at’)
But when tehre’s a sale going on, the entire string gets too long for one line. As can be seen here: http://www.deconstructionart.com/shop/
So ideally, what I would like is the crossed out regular price on line 1 and then the entire ‘Starts at <sale prize>’ on line 2. I’ve got a sneaky feeling this involves inserting a <br> somewehere, but I can’t seem to find the right place. So now I’m hoping you can find the solution.
This is the code as it is right now:
//Woocom: change variable prices from xxx.xx-yyy.yy to From XXX.XX
add_filter( ‘woocommerce_variable_sale_price_html’, ‘bbloomer_variation_price_format’, 10, 2 );
add_filter( ‘woocommerce_variable_price_html’, ‘bbloomer_variation_price_format’, 10, 2 );
function bbloomer_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( __( ‘Starting at %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( __( ‘Starting at %1$s’, ‘woocommerce’ ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );if ( $price !== $saleprice ) {
$price = ‘‘ . $saleprice . ‘<ins>’ . $price . ‘</ins>’;
}
return $price;
}October 16, 2016 at 10:01 am #1218213
Geert SParticipantThis reply has been marked as private.October 16, 2016 at 10:04 am #1218215
Geert SParticipantSolved! 🙂
After a lot of trying,. apparently it took writing this post for me to suddenly see a very likely place for the <br> and it worked! I’ve little idea what I’m doing, but sometimes I get things right…For curious co-users, the <br> goes here:
$price = ‘‘ . $saleprice . ‘<ins><br>’ . $price . ‘</ins>’;October 16, 2016 at 10:25 am #1218235
ThaiModeratorGlad you’ve sorted it out.
If you need anything else, please let us know 🙂
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1218211 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
