validatePricing(); } catch ( Exception $e ) { ?>
getMessage() ); ?>
renderBasePrice( $rule ); $this->renderTiers( $rule ); $this->renderQuantityLimits( $rule ); } protected function renderBasePrice( GlobalPricingRule $rule ) { $chips = array(); if ( 'flat' === $rule->getPricingType() ) { if ( $rule->getRegularPrice() ) { $chips[] = __( 'Regular', 'tier-pricing-table' ) . ' ' . wc_price( $rule->getRegularPrice() ) . ''; } if ( $rule->getSalePrice() ) { $chips[] = __( 'Sale', 'tier-pricing-table' ) . ' ' . wc_price( $rule->getSalePrice() ) . ''; } } elseif ( $rule->getDiscount() ) { $chips[] = sprintf( /* translators: 1: percentage, 2: "sale price" or "regular price" */ __( 'Discount %1$s%% off the %2$s', 'tier-pricing-table' ), esc_html( $rule->getDiscount() ), 'sale_price' === $rule->getDiscountType() ? __( 'sale price', 'tier-pricing-table' ) : __( 'regular price', 'tier-pricing-table' ) ); } if ( $chips ) { $this->renderLine( __( 'Base price', 'tier-pricing-table' ), $chips ); } } /** * The tiers as a small table: quantity ranges (or thresholds, per the plugin's quantity type * setting) and the price or discount, with a base row for the quantities below the first tier. */ protected function renderTiers( GlobalPricingRule $rule ) { $percentage = 'percentage' === $rule->getTieredPricingType(); $tiers = $percentage ? $rule->getPercentageTieredPricingRules() : $rule->getFixedTieredPricingRules(); if ( empty( $tiers ) ) { return; } ksort( $tiers ); $quantities = array_map( 'intval', array_keys( $tiers ) ); $values = array_values( $tiers ); $minimum = $rule->getMinimum() ? (int) $rule->getMinimum() : 1; $ranges = 'range' === $this->getContainer()->getSettings()->get( 'quantity_type', 'range' ); // what the customer pays below the first tier $base = __( 'Regular price', 'tier-pricing-table' ); if ( 'flat' === $rule->getPricingType() ) { if ( $rule->getSalePrice() ) { $base = wc_price( $rule->getSalePrice() ); } elseif ( $rule->getRegularPrice() ) { $base = wc_price( $rule->getRegularPrice() ); } } elseif ( $rule->getDiscount() ) { /* translators: %s: percentage */ $base = esc_html( sprintf( __( '%s%% off', 'tier-pricing-table' ), $rule->getDiscount() ) ); } $rows = array(); if ( $quantities[0] > $minimum ) { $rows[] = array( $this->quantityLabel( $minimum, $quantities[0] - 1, $ranges ), $base, false ); } foreach ( $quantities as $index => $quantity ) { $next = $quantities[ $index + 1 ] ?? null; $label = null === $next ? number_format_i18n( $quantity ) . '+' : $this->quantityLabel( $quantity, $next - 1, $ranges ); $value = $percentage ? esc_html( $values[ $index ] . '%' ) : wc_price( $values[ $index ] ); $rows[] = array( $label, $value, true ); } $label = sprintf( /* translators: 1: "fixed" or "percentage", 2: "individual" or "mix & match" */ __( 'Tiers (%1$s, %2$s)', 'tier-pricing-table' ), $percentage ? __( 'percentage', 'tier-pricing-table' ) : __( 'fixed', 'tier-pricing-table' ), 'individual' === $rule->getApplyingType() ? __( 'individual', 'tier-pricing-table' ) : __( 'mix & match', 'tier-pricing-table' ) ); ?>
getMinimum() ) { /* translators: %s: quantity */ $chips[] = sprintf( __( 'Min %s', 'tier-pricing-table' ), esc_html( number_format_i18n( $rule->getMinimum() ) ) ); } if ( ! empty( $rule->data['maximum_quantity'] ) ) { /* translators: %s: quantity */ $chips[] = sprintf( __( 'Max %s', 'tier-pricing-table' ), esc_html( number_format_i18n( (int) $rule->data['maximum_quantity'] ) ) ); } if ( ! empty( $rule->data['group_of_quantity'] ) ) { /* translators: %s: quantity */ $chips[] = sprintf( __( 'Step %s', 'tier-pricing-table' ), esc_html( number_format_i18n( (int) $rule->data['group_of_quantity'] ) ) ); } if ( $chips ) { $this->renderLine( __( 'Quantity', 'tier-pricing-table' ), $chips ); } } /** * @param string[] $chips Escaped HTML. */ protected function renderLine( string $label, array $chips ) { ?>