| @@ -76,10 +76,15 @@ | ||
| 76 | 76 | // "Count Quantity As" combined / variations: eligibility gates the flat price discount. |
| 77 | 77 | if ( isset( $this->item['disco_forced_qty'] ) ) { |
| 78 | 78 | $forced = max( 0, (int) $this->item['disco_forced_qty'] ); |
| 79 | 79 | $this->discounted_quantities = $forced; |
| 80 | + $amount = 0.0; | |
| 80 | 81 | |
| 81 | - return $forced > 0 ? (float) $fixed_discount : 0; | |
| 82 | + if ( $forced > 0 ) { | |
| 83 | + $amount = (float) $fixed_discount * $this->pooled_bundle_count( $forced ); | |
| 84 | + } | |
| 85 | + | |
| 86 | + return apply_filters( 'disco_final_discounted_amount', $amount, 'fixed_price' ); | |
| 82 | 87 | } |
| 83 | 88 | $min = $this->rule['min'] ? (int) $this->rule['min'] : 0; // phpcs:ignore |
| 84 | 89 | $max = $this->rule['max'] ? (int) $this->rule['max'] : 0; // phpcs:ignore |
| 85 | 90 | $recursive = isset( $this->rule['recursive'] ) && 'yes' === $this->rule['recursive']; // phpcs:ignore |
| @@ -103,9 +108,9 @@ | ||
| 103 | 108 | } |
| 104 | 109 | |
| 105 | 110 | $this->discounted_quantities = $discount_for_quantities; |
| 106 | 111 | |
| 107 | - return $discount_amount; | |
| 112 | + return apply_filters( 'disco_final_discounted_amount', $discount_amount, 'fixed_price' ); | |
| 108 | 113 | } |
| 109 | 114 | |
| 110 | 115 | /** |
| 111 | 116 | * Calculate Price. |
| @@ -171,6 +176,34 @@ | ||
| 171 | 176 | // } |
| 172 | 177 | // |
| 173 | 178 | // return $total_price; |
| 174 | 179 | // } |
| 180 | + | |
| 181 | + /** | |
| 182 | + * How many times a flat amount is charged for a pooled group. | |
| 183 | + * | |
| 184 | + * The pooled path hands this class the whole qualifying quantity on a single | |
| 185 | + * line, so the bundle count comes from that quantity rather than from a per | |
| 186 | + * line multiplier. A non recursive rule is charged once however large the | |
| 187 | + * pool; a recursive one is charged once per whole bundle in it. | |
| 188 | + * | |
| 189 | + * @param int $pooled_quantity Qualifying quantity across the pooled lines. | |
| 190 | + */ | |
| 191 | + private function pooled_bundle_count( int $pooled_quantity ): int { | |
| 192 | + if ( ! isset( $this->rule['recursive'] ) || 'yes' !== $this->rule['recursive'] ) { | |
| 193 | + return 1; | |
| 194 | + } | |
| 195 | + | |
| 196 | + $minimum = 0; | |
| 197 | + | |
| 198 | + if ( isset( $this->rule['min'] ) ) { | |
| 199 | + $minimum = absint( $this->rule['min'] ); | |
| 200 | + } | |
| 201 | + | |
| 202 | + if ( $minimum < 1 ) { | |
| 203 | + return 1; | |
| 204 | + } | |
| 205 | + | |
| 206 | + return max( 1, (int) floor( $pooled_quantity / $minimum ) ); | |
| 207 | + } | |
| 175 | 208 | |
| 176 | 209 | } |