• Resolved paolo8913

    (@paolo8913)


    Hi i want add the discount badge on the right on the price.
    I used this function, but it appear UNDER the price and not at its right. How i can modify it to let the discount price goes to the right?

    add_filter( ‘woocommerce_get_price_html’, ‘change_displayed_sale_price_html’, 10, 2 );
    function change_displayed_sale_price_html( $price, $product ) {
    // Only on sale products on frontend and excluding min/max price on variable products
    if( is_single() && $product->is_on_sale() && ! is_admin() && ! $product->is_type(‘variable’)){
    // Get product prices
    $regular_price = (float) $product->get_regular_price(); // Regular price
    $sale_price = (float) $product->get_price(); // Active price (the “Sale price” when on-sale)

    // “Saving price” calculation and formatting
    $saving_price = wc_price( $regular_price – $sale_price );

    // “Saving Percentage” calculation and formatting
    $precision = 1; // Max number of decimals
    $saving_percentage = round( 100 – ( $sale_price / $regular_price * 100 ), 1 ) . ‘%’;

    // Append to the formated html price
    $price .= sprintf( __(‘<p class=”saved-sale”>Risparmia %s (-%s)</p>’, ‘woocommerce’ ), $saving_price, $saving_percentage );
    }
    return $price;
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    Hi there! ??

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers!

    Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    We’ve not seen any activity on this thread for a while, so I’m marking this thread as resolved.

    Hopefully, you were able to find a solution to your problem! If you have further questions, please feel free to open a new topic.

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘&DISCOUNT on the right of price’ is closed to new replies.