Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #2776752
Programatically change sale label
Closed

Comments

  • Ivan O'Donoghue started the conversation

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


  •  767
    Janilyn replied

    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

  •  1,226
    Dustin replied

    Hi Ivan,

    I'm so sorry for the late reply!

    Our bundle has the type is "woosb".

    Best regards,
    Dustin