Comments Ivan O'Donoghue started the conversationMay 14, 2021 at 11:36amHi, I'm trying to change the sale tag to show a percentage discount like I have done for other simple/variable products. I added the wpcb type to my existing code, but unsurpsisingly, it didn't work. Wondering if there is an easy way to do this? /* Change sale price to Save! */ add_filter('woocommerce_sale_flash', 'woocommerce_custom_sale_text', 10, 3); function woocommerce_custom_sale_text($text, $post, $_product) { 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' ) || $product->is_type('wcpb')) { $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 ) return "<span class='onsale'>SAVE " . round($max_percentage) . "%</span>"; //return '<span class="onsale">SAVE!</span>'; } 767Janilyn repliedMay 17, 2021 at 4:39amHi Ivan, Thank you for contacting WPClever Support Forum. We’ve received your ticket and assigned one of our developers to help you with that. He’ll be looking into your question and responding with specific instructions as soon as possible. Please stay patient as we're having very heavy workloads, it might take some time for our developers to reach back. Best regards.Janilyn T. - WPClever Support Agent 1,226Dustin repliedMay 30, 2021 at 3:47amHi Ivan,I'm so sorry for the late reply!Our bundle has the type is "woosb".Best regards,Dustin Sign in to reply ...
Hi,
I'm trying to change the sale tag to show a percentage discount like I have done for other simple/variable products. I added the wpcb type to my existing code, but unsurpsisingly, it didn't work. Wondering if there is an easy way to do this?
/* Change sale price to Save! */ add_filter('woocommerce_sale_flash', 'woocommerce_custom_sale_text', 10, 3); function woocommerce_custom_sale_text($text, $post, $_product) { 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' ) || $product->is_type('wcpb')) { $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 ) return "<span class='onsale'>SAVE " . round($max_percentage) . "%</span>"; //return '<span class="onsale">SAVE!</span>'; }
Hi Ivan,
Thank you for contacting WPClever Support Forum.
We’ve received your ticket and assigned one of our developers to help you with that.
He’ll be looking into your question and responding with specific instructions as soon as possible.
Please stay patient as we're having very heavy workloads, it might take some time for our developers to reach back.
Best regards.
Janilyn T. - WPClever Support Agent
Hi Ivan,
I'm so sorry for the late reply!
Our bundle has the type is "woosb".
Best regards,
Dustin