| @@ -30,9 +30,8 @@ | ||
| 30 | 30 | // Calculate product price in cart by pricing rules |
| 31 | 31 | add_action( 'woocommerce_before_calculate_totals', [ $this, 'calculateTotals' ], 10, 3 ); |
| 32 | 32 | add_action( 'woocommerce_before_mini_cart_contents', [ $this, 'miniCartSubTotal' ], 10, 3 ); |
| 33 | 33 | add_filter( 'woocommerce_cart_item_price', [ $this, 'calculateItemPrice' ], 10, 2 ); |
| 34 | - | |
| 35 | 34 | } |
| 36 | 35 | |
| 37 | 36 | /** |
| 38 | 37 | * Calculate price by quantity rules |
| @@ -42,9 +41,13 @@ | ||
| 42 | 41 | public function calculateTotals( $cart ) { |
| 43 | 42 | |
| 44 | 43 | if ( ! empty( $cart->cart_contents ) ) { |
| 45 | 44 | foreach ( $cart->cart_contents as $key => $cart_item ) { |
| 46 | - if ( $cart_item['data'] instanceof WC_Product ) { | |
| 45 | + | |
| 46 | + $needPriceRecalculation = apply_filters( 'tier_pricing_table/cart/need_price_recalculation', true, $cart_item ); | |
| 47 | + | |
| 48 | + if ( $cart_item['data'] instanceof WC_Product && $needPriceRecalculation ) { | |
| 49 | + | |
| 47 | 50 | $product_id = ! empty( $cart_item['variation_id'] ) ? $cart_item['variation_id'] : $cart_item['product_id']; |
| 48 | 51 | |
| 49 | 52 | $new_price = PriceManager::getPriceByRules( $cart_item['quantity'], $product_id ); |
| 50 | 53 | |
| @@ -69,9 +72,12 @@ | ||
| 69 | 72 | * |
| 70 | 73 | * @return string |
| 71 | 74 | */ |
| 72 | 75 | public function calculateItemPrice( $price, $cart_item ) { |
| 73 | - if ( $cart_item['data'] instanceof WC_Product ) { | |
| 76 | + | |
| 77 | + $needPriceRecalculation = apply_filters( 'tier_pricing_table/cart/need_price_recalculation/item', true, $cart_item ); | |
| 78 | + | |
| 79 | + if ( $cart_item['data'] instanceof WC_Product && $needPriceRecalculation ) { | |
| 74 | 80 | |
| 75 | 81 | $new_price = PriceManager::getPriceByRules( $cart_item['quantity'], $cart_item['data']->get_id() ); |
| 76 | 82 | |
| 77 | 83 | // To get real product price |