Show “Bulk discounts” badge for Woodmart theme
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
add_action('init', function() { if ( false !== ( $priority = has_action( 'woocommerce_sale_flash','woodmart_product_label' ) ) ) { if ( remove_action( 'woocommerce_sale_flash','woodmart_product_label', $priority ) ) { add_action( 'woocommerce_sale_flash', 'wdp_product_label' ); } } }); function lmb_customize_badge( $badge ) { global $product; if ( ! function_exists( 'adp_functions' ) ) { return $badge; } $helper = adp_functions(); $rules = $helper->getActiveRulesForProduct( $product, 999.0 ); if ( empty( $rules ) ) { return $badge; } $changeBadgeText = false; foreach( $rules as $r ) { $adjustmentHandler = $r->getProductRangeAdjustmentHandler(); if ( $adjustmentHandler && $adjustmentHandler->getType() === $adjustmentHandler::TYPE_BULK ) { $changeBadgeText = true; break; } } if ( $changeBadgeText ) { return 'Bulk discounts'; // modify this line only } return $badge; } function wdp_product_label() { global $product; $output = array(); $product_attributes = woodmart_get_product_attributes_label(); $percentage_label = woodmart_get_opt( 'percentage_label' ); if ( $product->is_on_sale() ) { $percentage = ''; if ( $product->get_type() == 'variable' && $percentage_label ) { $available_variations = $product->get_variation_prices(); $max_percentage = 0; foreach( $available_variations['regular_price'] as $key => $regular_price ) { $sale_price = $available_variations['sale_price'][$key]; if ( $sale_price < $regular_price ) { $percentage = round( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 ); if ( $percentage > $max_percentage ) { $max_percentage = $percentage; } } } $percentage = $max_percentage; } elseif ( ( $product->get_type() == 'simple' || $product->get_type() == 'external' ) && $percentage_label ) { $percentage = round( ( ( $product->get_regular_price() - $product->get_sale_price() ) / $product->get_regular_price() ) * 100 ); } if ( $percentage ) { $output[] = '<span class="onsale product-label">' . lmb_customize_badge( '-' . $percentage . '%' ) . '</span>'; } else { $output[] = '<span class="onsale product-label">' . lmb_customize_badge ( esc_html__( 'Sale', 'woodmart' ) ) . '</span>'; } } if( !$product->is_in_stock() ){ $output[] = '<span class="out-of-stock product-label">' . esc_html__( 'Sold out', 'woodmart' ) . '</span>'; } if ( $product->is_featured() && woodmart_get_opt( 'hot_label' ) ) { $output[] = '<span class="featured product-label">' . esc_html__( 'Hot', 'woodmart' ) . '</span>'; } if ( get_post_meta( get_the_ID(), '_woodmart_new_label', true ) && woodmart_get_opt( 'new_label' ) ) { $output[] = '<span class="new product-label">' . esc_html__( 'New', 'woodmart' ) . '</span>'; } if ( $product_attributes ) { foreach ( $product_attributes as $attribute ) { $output[] = $attribute; } } if ( $output ) { echo '<div class="product-labels labels-' . woodmart_get_opt( 'label_shape' ) . '">' . implode( '', $output ) . '</div>'; } } |