PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.17
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.17
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 1.3.52 1.3.51 1.3.50 1.3.49 1.3.48 All 180 releases
← All changes | app/Calc/CalcFixedPrice.php +35 -2 1.4.61.4.17 View file →
@@ -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 }