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 +42 -1 1.3.531.4.17 View file →
@@ -71,8 +71,21 @@
71 71 $discount_amount = 0;
72 72 $fixed_discount = $this->rule['discount_value'];
73 73 $price = $this->item['data']->get_price(); // phpcs:ignore
74 74 $quantity = (int) $this->item['quantity']; // phpcs:ignore
75 +
76 + // "Count Quantity As" combined / variations: eligibility gates the flat price discount.
77 + if ( isset( $this->item['disco_forced_qty'] ) ) {
78 + $forced = max( 0, (int) $this->item['disco_forced_qty'] );
79 + $this->discounted_quantities = $forced;
80 + $amount = 0.0;
81 +
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' );
87 + }
75 88 $min = $this->rule['min'] ? (int) $this->rule['min'] : 0; // phpcs:ignore
76 89 $max = $this->rule['max'] ? (int) $this->rule['max'] : 0; // phpcs:ignore
77 90 $recursive = isset( $this->rule['recursive'] ) && 'yes' === $this->rule['recursive']; // phpcs:ignore
78 91
@@ -95,9 +108,9 @@
95 108 }
96 109
97 110 $this->discounted_quantities = $discount_for_quantities;
98 111
99 - return $discount_amount;
112 + return apply_filters( 'disco_final_discounted_amount', $discount_amount, 'fixed_price' );
100 113 }
101 114
102 115 /**
103 116 * Calculate Price.
@@ -163,6 +176,34 @@
163 176 // }
164 177 //
165 178 // return $total_price;
166 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 + }
167 208
168 209 }