rule['from'] ) { break; } } if ( $b ) { $f = $b * $rule['from']; $a = $q - $f - $remaining; } else { $f = $rule['from']; $a = 0; } } break; case 'variation': if ( $q > $cart_item['quantity'] ) { //The quantity of the variation in the cart is greater than this line item quantity. More than one variation is in the cart //for this product. Handle the same as if the product is in the cart more than once. $b = floor( $q / ( $rule['from'] + $rule['adjust'] ) ); $a = $b * $rule['adjust']; $f = $b * $rule['from']; if ( isset( $this->used_rules[ $rule_set_id ] ) ) { $a = $a - $this->used_rules[ $rule_set_id ]; } } else { //How many blocks are available. $b = floor( $q / ( $rule['from'] + $rule['adjust'] ) ); $a = $b * $rule['adjust']; $f = $b * $rule['from']; } break; } $rq = $f; //required quantity equals the amount of fixed price items we need to have. } else { switch ( $collector['type'] ) { case 'cart_item': $f = $rule['from']; $a = max( 0, min( $rule['adjust'], $cart_item['quantity'] - $f ) ); $rq = $f + min( $a, $cart_item['quantity'] - $f ); break; case 'cat': $f = $rule['from']; $a = $rule['adjust']; if ( isset( $this->used_rules[ $rule_set_id ] ) ) { $a = $a - $this->used_rules[ $rule_set_id ]; } $terms = $this->get_product_category_ids( $cart_item['data'] ); if ( count( array_intersect( $collector['args']['cats'], $terms ) ) > 0 ) { $rq = $f + $a; } else { $rq = $f; } break; case 'product': $f = $rule['from']; $a = min( $rule['adjust'], max( 0, $q - $f ) ); if ( isset( $this->used_rules[ $rule_set_id ] ) ) { $a = $a - $this->used_rules[ $rule_set_id ]; } $rq = $f + $a; //required quantity is the amount of fixed price items + the amount that will be adjusted. break; case 'variation': $f = $rule['from']; $a = min( $rule['adjust'], max( 0, $q - $f ) ); if ( isset( $this->used_rules[ $rule_set_id ] ) ) { $a = $a - $this->used_rules[ $rule_set_id ]; } $rq = $f + $a; //required quantity is the amount of fixed price items + the amount that will be adjusted. break; } } if ( $a > $cart_item['quantity'] ) { $a = $cart_item['quantity']; } if ( $q >= $rq ) { $amount = apply_filters( 'woocommerce_dynamic_pricing_get_rule_amount', $rule['amount'], $rule, $cart_item, $this ); $num_decimals = apply_filters( 'woocommerce_dynamic_pricing_get_decimals', (int) get_option( 'woocommerce_price_num_decimals' ) ); switch ( $rule['type'] ) { case 'fixed_adjustment': $adjusted = floatval( $price ) - floatval( $amount ); $adjusted = $adjusted >= 0 ? $adjusted : 0; $line_total = 0; $full_price_quantity = $cart_item['quantity'] - $a; $discount_quantity = $a; $line_total = ( $discount_quantity * $adjusted ) + ( $full_price_quantity * $price ); $result = $line_total / $cart_item['quantity']; $result = $result >= 0 ? $result : 0; $this->used_rules[ $rule_set_id ] = isset( $this->used_rules[ $rule_set_id ] ) ? $this->used_rules[ $rule_set_id ] + $a : $a; break; case 'percent_adjustment': $amount = $amount / 100; $adjusted = round( floatval( $price ) - ( floatval( $amount ) * $price ), (int) $num_decimals ); $line_total = 0; $full_price_quantity = $cart_item['quantity'] - $a; $discount_quantity = $a; $line_total = ( $discount_quantity * $adjusted ) + ( $full_price_quantity * $price ); $result = $line_total / $cart_item['quantity']; $this->used_rules[ $rule_set_id ] = isset( $this->used_rules[ $rule_set_id ] ) ? $this->used_rules[ $rule_set_id ] + $a : $a; break; case 'fixed_price': $adjusted = round( $amount, (int) $num_decimals ); $line_total = 0; $full_price_quantity = $cart_item['quantity'] - $a; $discount_quantity = $a; $line_total = ( $discount_quantity * $adjusted ) + ( $full_price_quantity * $price ); $result = $line_total / $cart_item['quantity']; $result = $result >= 0 ? $result : 0; $this->used_rules[ $rule_set_id ] = isset( $this->used_rules[ $rule_set_id ] ) ? $this->used_rules[ $rule_set_id ] + $a : $a; break; default: $result = false; break; } } } } return $result; } protected function get_quantity_to_compare( $cart_item, $collector, $set = null ) { global $woocommerce_pricing, $woocommerce; $quantity = 0; switch ( $collector['type'] ) { case 'cart_item': $quantity = $cart_item['quantity']; break; case 'cat' : if ( isset( $collector['args'] ) && isset( $collector['args']['cats'] ) && is_array( $collector['args']['cats'] ) ) { $quantity = 0; if ( isset( $collector['args'] ) && isset( $collector['args']['cats'] ) && is_array( $collector['args']['cats'] ) ) { $temp_cart = WC_Dynamic_Pricing_Compatibility::WC()->cart->cart_contents; foreach ( $temp_cart as $lck => $check_cart_item ) { if ( is_object_in_term( $check_cart_item['product_id'], 'product_cat', $collector['args']['cats'] ) ) { if ( apply_filters( 'woocommerce_dynamic_pricing_count_categories_for_cart_item', true, $cart_item, $lck ) ) { $quantity += (int) $check_cart_item['quantity']; } } } } } break; case 'product': if ( WC_Dynamic_Pricing_Counter::get_product_count( $cart_item['product_id'] ) ) { $quantity += WC_Dynamic_Pricing_Counter::get_product_count( $cart_item['product_id'] ); } break; case 'variation': if ( WC_Dynamic_Pricing_Counter::get_variation_count( $cart_item['variation_id'] ) ) { $quantity += WC_Dynamic_Pricing_Counter::get_variation_count( $cart_item['variation_id'] ); } break; } return apply_filters( 'woocommerce_dynamic_pricing_get_quantity_for_cart_item', $quantity, $cart_item, $collector, $set ); } }