PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.22
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.22
1.4.22 1.4.21 1.4.20 1.4.19 1.4.18 1.4.17 1.4.16 1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 All 185 releases
← All changes | app/Calc/CalcFixed.php +35 -2 1.4.15 → 1.4.22 View file →
@@ -86,10 +86,15 @@
86 86 */
87 87 if ( isset( $this->item['disco_forced_qty'] ) ) {
88 88 $forced = max( 0, (int) $this->item['disco_forced_qty'] );
89 89 $this->discounted_quantities = $forced;
90 + $amount = 0.0;
90 91
91 - return apply_filters( 'disco_final_discounted_amount', $forced > 0 ? (float) $fixed_discount : 0, 'fixed' );
92 + if ( $forced > 0 ) {
93 + $amount = (float) $fixed_discount * $this->pooled_bundle_count( $forced );
94 + }
95 +
96 + return apply_filters( 'disco_final_discounted_amount', $amount, 'fixed' );
92 97 }
93 98
94 99 $min = $this->rule['min'] ? (int) $this->rule['min'] : 0; // phpcs:ignore
95 100 $max = $this->rule['max'] ? (int) $this->rule['max'] : 0; // phpcs:ignore
@@ -124,9 +129,9 @@
124 129 * This is to ensure that the discount for selected item for BOGO discount.
125 130 * Here no need to check for min and max quantity.
126 131 */
127 132 if (
128 - $this->discount_intent === 'BuyXGetY'
133 + 'BuyXGetY' === $this->discount_intent
129 134 && ! empty( $rule_ids )
130 135 && (
131 136 in_array( $item_id, $rule_ids, true )
132 137 || $this->is_in_category( $item_id, $rule_ids )
@@ -180,7 +185,35 @@
180 185 return $this->item['line_subtotal'] - $discount;
181 186 }
182 187
183 188 return 0.0;
189 + }
190 +
191 + /**
192 + * How many times a flat amount is charged for a pooled group.
193 + *
194 + * The pooled path hands this class the whole qualifying quantity on a single
195 + * line, so the bundle count comes from that quantity rather than from a per
196 + * line multiplier. A non recursive rule is charged once however large the
197 + * pool; a recursive one is charged once per whole bundle in it.
198 + *
199 + * @param int $pooled_quantity Qualifying quantity across the pooled lines.
200 + */
201 + private function pooled_bundle_count( int $pooled_quantity ): int {
202 + if ( ! isset( $this->rule['recursive'] ) || 'yes' !== $this->rule['recursive'] ) {
203 + return 1;
204 + }
205 +
206 + $minimum = 0;
207 +
208 + if ( isset( $this->rule['min'] ) ) {
209 + $minimum = absint( $this->rule['min'] );
210 + }
211 +
212 + if ( $minimum < 1 ) {
213 + return 1;
214 + }
215 +
216 + return max( 1, (int) floor( $pooled_quantity / $minimum ) );
184 217 }
185 218
186 219 }