| @@ -176,8 +176,23 @@ | ||
| 176 | 176 | public static function getProductQtyMin( $productId, ?string $context = 'view' ) : ?int { |
| 177 | 177 | return null; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | + public static function isProductMixAndMatch( $productId ) { | |
| 181 | + $mixAndMatch = get_post_meta( $productId, '_tiered_price_mix_and_match_minimum', true ); | |
| 182 | + if ( '' !== $mixAndMatch ) { | |
| 183 | + return 'yes' === $mixAndMatch; | |
| 184 | + } | |
| 185 | + $product = wc_get_product( $productId ); | |
| 186 | + if ( $product && $product->is_type( 'variation' ) ) { | |
| 187 | + $parentMixAndMatch = get_post_meta( $product->get_parent_id(), '_tiered_price_mix_and_match_minimum', true ); | |
| 188 | + if ( '' !== $parentMixAndMatch ) { | |
| 189 | + return 'yes' === $parentMixAndMatch; | |
| 190 | + } | |
| 191 | + } | |
| 192 | + return CalculationLogic::isMixAndMatchMinimumEnabled(); | |
| 193 | + } | |
| 194 | + | |
| 180 | 195 | /** |
| 181 | 196 | * Update product minimum quantity |
| 182 | 197 | * |
| 183 | 198 | * @param int $productId |
| @@ -247,19 +262,23 @@ | ||
| 247 | 262 | * Set minimum quantity for the product |
| 248 | 263 | * |
| 249 | 264 | ****************************************/ |
| 250 | 265 | $minimum = self::getProductQtyMin( $productId ); |
| 266 | + $isMixAndMatch = self::isProductMixAndMatch( $productId ); | |
| 251 | 267 | // If product does not have minimum quantity, check parent product |
| 252 | 268 | if ( !$minimum ) { |
| 253 | - $product = ( $product ? $product : wc_get_product( $productId ) ); | |
| 254 | 269 | if ( $product && TierPricingTablePlugin::isVariationProductSupported( $product ) ) { |
| 255 | - $minimum = self::getProductQtyMin( $product->get_parent_id() ); | |
| 256 | - if ( $minimum ) { | |
| 257 | - $pricingRule->logPricingModification( 'Using parent product minimum quantity' ); | |
| 270 | + $parentIsMixAndMatch = $isMixAndMatch; | |
| 271 | + if ( !$parentIsMixAndMatch ) { | |
| 272 | + $minimum = self::getProductQtyMin( $product->get_parent_id() ); | |
| 273 | + if ( $minimum ) { | |
| 274 | + $pricingRule->logPricingModification( 'Using parent product minimum quantity' ); | |
| 275 | + } | |
| 258 | 276 | } |
| 259 | 277 | } |
| 260 | 278 | } |
| 261 | 279 | $pricingRule->setMinimum( $minimum ); |
| 280 | + $pricingRule->setMixAndMatchMinQuantity( $isMixAndMatch ); | |
| 262 | 281 | /***************************************** |
| 263 | 282 | * |
| 264 | 283 | * Services that modify pricing rule |
| 265 | 284 | * |
| @@ -265,8 +284,9 @@ | ||
| 265 | 284 | * |
| 266 | 285 | * @hooked QuantityManager - 1: Added maximum and quantity step information. |
| 267 | 286 | * @hooked CategoryTierAddon - 10: Filter with category-based rules |
| 268 | 287 | * @hooked RoleBasedPricingAddon - 20: Filter with role-based rules |
| 288 | + * @hooked RoleBasedPricingAddon - 25: Filter with customer-based rules | |
| 269 | 289 | * @hooked GlobalPricingService - 30: Filter with global rules |
| 270 | 290 | * |
| 271 | 291 | *****************************************/ |
| 272 | 292 | $pricingRule = apply_filters( 'tiered_pricing_table/price/pricing_rule', $pricingRule, $productId ); |