Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1153150

    Hi,
    Is it possible to show a discount percentage?

    When i put in a discount price it says 100 – with a strip true and behind the new price.
    This is “fine” but u would like it if it shows somewhere that this is 25% is this possible?
    https://thehorsestore.nl/product/la-valencio-jas-lang-marcella/

    thanks for your help
    greatz myrna

    #1153408

    Hey thehorsestore,

    This answer would likely be better found in the WooCommerce forums.

    Best regards,
    Jordan Shannon

    #1155361

    Thanks! i figured it out :-)

    add_filter( ‘woocommerce_sale_flash’, ‘add_percentage_to_sale_badge’, 20, 3 );
    function add_percentage_to_sale_badge( $html, $post, $product ) {
    if( $product->is_type(‘variable’)){
    $percentages = array();

    // Get all variation prices
    $prices = $product->get_variation_prices();

    // Loop through variation prices
    foreach( $prices[‘price’] as $key => $price ){
    // Only on sale variations
    if( $prices[‘regular_price’][$key] !== $price ){
    // Calculate and set in the array the percentage for each variation on sale
    $percentages[] = round(100 – ($prices[‘sale_price’][$key] / $prices[‘regular_price’][$key] * 100));
    }
    }
    // We keep the highest value
    $percentage = max($percentages) . ‘%’;
    } else {
    $regular_price = (float) $product->get_regular_price();
    $sale_price = (float) $product->get_sale_price();

    $percentage = round(100 – ($sale_price / $regular_price * 100)) . ‘%’;
    }
    return ‘<span class=”onsale”>’ . esc_html__( ‘-‘, ‘woocommerce’ ) . ‘ ‘ . $percentage . ‘</span>’;
    }

    #1155482

    Hi,

    Great, I’m glad that you found a solution and thanks for sharing. Please let us know if you should need any further help on the topic or if we can close it.

    Best regards,
    Rikard

    #1157612

    Thanks, you can close the topic

    #1157617

    Hi,
    Glad to hear we will close this now. Thank you for using Enfold.

    For your information, you can take a look at Enfold documentation here
    For any other questions or issues, feel free to start new threads in the Enfold forum and we will gladly try to help you :)

    Best regards,
    Mike

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Discount percentage’ is closed to new replies.