Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1218211
    Geert S
    Participant

    Hi 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;
    }

    #1218213
    Geert S
    Participant
    This reply has been marked as private.
    #1218215
    Geert S
    Participant

    Solved! 🙂
    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>’;

    #1218235
    Thai
    Moderator

    Glad you’ve sorted it out.

    If you need anything else, please let us know 🙂

  • <script> jQuery(function($){ $("#no-reply-1218211 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>