Support » Developing with WordPress » Discount in percentage on product page B2B

  • I use your plugin B2B for WooCommerce for my webshop and I need to display the discount in percentage on product page. I have a script that works for sale price but not for wholesale price. Can you help me adjust the script to work for wholesale too?

    add_action( ‘woocommerce_sale_flash’, ‘sale_badge_percentage’, 25 );

    function sale_badge_percentage() {
    global $product;
    if ( ! $product->is_on_sale() ) return;
    if ( $product->is_type( ‘simple’ ) ) {
    $max_percentage = ( ( $product->get_regular_price() – $product->get_sale_price() ) / $product->get_regular_price() ) * 100;
    } elseif ( $product->is_type( ‘variable’ ) ) {
    $max_percentage = 0;
    foreach ( $product->get_children() as $child_id ) {
    $variation = wc_get_product( $child_id );
    $price = $variation->get_regular_price();
    $sale = $variation->get_sale_price();
    if ( $price != 0 && ! empty( $sale ) ) $percentage = ( $price – $sale ) / $price * 100;
    if ( $percentage > $max_percentage ) {
    $max_percentage = $percentage;
    }
    }
    }
    if ( $max_percentage > 0 ) echo “-” . round($max_percentage) . “%”; // If you would like to show -40% off then add text after % sign
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    Since that is a commercial theme or plugin, we ask that you please go to their official support channel, so you can get support from the people who know it best: https://woocommerce.com/my-account/create-a-ticket/

    Forum volunteers do not have access to commercial products, so they would not know why it is not working correctly. Other community members who may have faced your issue might be able to help you, but your best bet is your product’s developer. We encourage you to use the official support venues, as it allows the developers to be aware of issues with their code and gives back to the community in a more robust way.

    Thread Starter disebecic

    (@disebecic)

    This is a support response: “I am afraid this feature is not available in our extension to show the % discount badge based on discount value set by our extension. If you are interested in this customization let me know I’ll get back to you with an estimated development time and pricing.”

    They didn’t help me adjust the script, so if anyone has any ideas, any help would be great.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.