| @@ -41,16 +41,12 @@ | ||
| 41 | 41 | public function calculateTotals( $cart ) { |
| 42 | 42 | |
| 43 | 43 | if ( ! empty( $cart->cart_contents ) ) { |
| 44 | 44 | foreach ( $cart->cart_contents as $key => $cart_item ) { |
| 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 | - | |
| 45 | + if ( $cart_item['data'] instanceof WC_Product ) { | |
| 50 | 46 | $product_id = ! empty( $cart_item['variation_id'] ) ? $cart_item['variation_id'] : $cart_item['product_id']; |
| 51 | 47 | |
| 52 | - $new_price = PriceManager::getPriceByRules( $this->getTotalProductCount($cart_item), $product_id, 'cart' ); | |
| 48 | + $new_price = PriceManager::getPriceByRules( $cart_item['quantity'], $product_id ); | |
| 53 | 49 | |
| 54 | 50 | if ( $new_price !== false ) { |
| 55 | 51 | $cart_item['data']->set_price( $new_price ); |
| 56 | 52 | } |
| @@ -58,33 +54,8 @@ | ||
| 58 | 54 | } |
| 59 | 55 | } |
| 60 | 56 | } |
| 61 | 57 | |
| 62 | - /** | |
| 63 | - * Get total product count depend on user's settings | |
| 64 | - * | |
| 65 | - * @param array $cart_item | |
| 66 | - * | |
| 67 | - * @return int | |
| 68 | - */ | |
| 69 | - public function getTotalProductCount( $cart_item ) { | |
| 70 | - | |
| 71 | - if ( $this->settings->get( 'summarize_variations', 'no' ) !== 'yes' ) { | |
| 72 | - return $cart_item['quantity']; | |
| 73 | - } | |
| 74 | - | |
| 75 | - $count = 0; | |
| 76 | - | |
| 77 | - foreach ( wc()->cart->cart_contents as $cart_content ) { | |
| 78 | - if ( $cart_content['product_id'] == $cart_item['product_id'] ) { | |
| 79 | - $count += $cart_content['quantity']; | |
| 80 | - } | |
| 81 | - } | |
| 82 | - | |
| 83 | - return (int) apply_filters( 'tier_pricing_table/cart/total_product_count', $count ); | |
| 84 | - } | |
| 85 | - | |
| 86 | - | |
| 87 | 58 | public function miniCartSubTotal() { |
| 88 | 59 | $cart = wc()->cart; |
| 89 | 60 | $cart->calculate_totals(); |
| 90 | 61 | } |
| @@ -97,14 +68,11 @@ | ||
| 97 | 68 | * |
| 98 | 69 | * @return string |
| 99 | 70 | */ |
| 100 | 71 | public function calculateItemPrice( $price, $cart_item ) { |
| 72 | + if ( $cart_item['data'] instanceof WC_Product ) { | |
| 101 | 73 | |
| 102 | - $needPriceRecalculation = apply_filters( 'tier_pricing_table/cart/need_price_recalculation/item', true, $cart_item ); | |
| 103 | - | |
| 104 | - if ( $cart_item['data'] instanceof WC_Product && $needPriceRecalculation ) { | |
| 105 | - | |
| 106 | - $new_price = PriceManager::getPriceByRules( $this->getTotalProductCount($cart_item), $cart_item['data']->get_id(), 'cart' ); | |
| 74 | + $new_price = PriceManager::getPriceByRules( $cart_item['quantity'], $cart_item['data']->get_id() ); | |
| 107 | 75 | |
| 108 | 76 | // To get real product price |
| 109 | 77 | $product = wc_get_product( $cart_item['data']->get_id() ); |
| 110 | 78 | |