settings = $settings; $this->hooks(); } protected function hooks() { // Calculate product price in cart by pricing rules add_action( 'woocommerce_before_calculate_totals', [ $this, 'calculateTotals' ], 10, 1 ); } /** * Calculate price by quantity rules * * @param WC_Cart $cart */ public function calculateTotals( $cart ) { if ( !empty($cart->cart_contents) ) { foreach ( $cart->cart_contents as $key => $cart_item ) { if ( $cart_item['data'] instanceof WC_Product ) { $product_id = ( !empty($cart_item['variation_id']) ? $cart_item['variation_id'] : $cart_item['product_id'] ); $new_price = PriceManager::getPriceByRules( $cart_item['quantity'], $product_id ); if ( $new_price !== false ) { $cart_item['data']->set_price( $new_price ); } } } } } }