Title: calculation logic
Last modified: February 4, 2026

---

# calculation logic

 *  Resolved [PetrP](https://wordpress.org/support/users/petrp/)
 * (@petrp)
 * [4 months ago](https://wordpress.org/support/topic/calculation-logic-4/)
 * hi, first let me tell that this is the very best plugin in its category; don’t
   look any further!
 * My problem: i have a products with one kind of attribute (‘year’) and all but
   one variations have the same price within that product.
   I selected the option‘
   consider product variations as one product’ so they can mix years in their case.
   The thing is though, that the plugin neglects the fact that one variation is 
   cheaper as it’s on sale (can’t put the cheap price as regular, it would not have
   the sale effect). So the plugin calculates the discount for 6 pieces also on 
   the already discounted variation. I also can’t opt to use regular price to calculate
   discounts, as that would be more expensive in total than the regular 5+1 sale.
   FYI: i excluded that particular variation via ‘exclusions’ in ‘pricing rules’,
   and effectively this results in no visible tiered possibility for this variation;
   still though the system will count it as being part of the general tier of this
   product. So, in short, would there be an option (php snippet?) to let the plugin
   exclude variations that are already on sale? I don’t see such an option.Thanks
   a lot!

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [Mykola Lukin](https://wordpress.org/support/users/bycrik/)
 * (@bycrik)
 * [4 months ago](https://wordpress.org/support/topic/calculation-logic-4/#post-18811163)
 * Hello [@petrp](https://wordpress.org/support/users/petrp/),
 * You can solve this using the
   `tiered_pricing_table/cart/total_product_count` 
   filter
 * The idea is to recalculate the quantity and **skip variations that are already
   on sale**, so they don’t contribute to tier thresholds. Or you can skip variations
   by your own logic.
 * Add this snippet to `functions.php` or a small custom plugin:
 *     ```wp-block-code
       add_filter(    'tiered_pricing_table/cart/total_product_count',    function ( $count, $cartItem ) {        if ( ! \TieredPricingTable\CalculationLogic::considerProductVariationAsOneProduct() ) {            return $count;        }        $count = 0;        foreach ( wc()->cart->get_cart() as $cart_content ) {            if ( $cart_content['product_id'] !== $cartItem['product_id'] ) {                continue;            }            $product = $cart_content['data'];            // Exclude variations that are already on sale            if ( $product && $product->is_on_sale() ) {                continue;            }            $count += (int) $cart_content['quantity'];        }        return $count;    },    10,    2);
       ```
   
 * **How it works:**
   The filter lets you override the quantity used for tier calculations.
   Here we loop through all variations of the same parent product (it means that
   is variations from the same parent product so we need to sum up their quantity)
   and exclude those that are on sale.
 * I hope this helps.
 *  Thread Starter [PetrP](https://wordpress.org/support/users/petrp/)
 * (@petrp)
 * [4 months ago](https://wordpress.org/support/topic/calculation-logic-4/#post-18812766)
 * Hi, thank you for the effort, but unfortunately it throws php errors.
   I have 
   PHP 8.5 latest WP & WC.
 *  Plugin Author [Mykola Lukin](https://wordpress.org/support/users/bycrik/)
 * (@bycrik)
 * [4 months ago](https://wordpress.org/support/topic/calculation-logic-4/#post-18812798)
 * Hello [@petrp](https://wordpress.org/support/users/petrp/),
 * Sorry, please find the updated code below:
 *     ```wp-block-code
       add_filter( 'tiered_pricing_table/cart/total_product_count', function ( $count, $cartItem ) {if ( ! \TierPricingTable\CalculationLogic::considerProductVariationAsOneProduct() ) {		return $count;		}		$count = 0;		foreach ( wc()->cart->get_cart() as $cart_content ) {			if ( $cart_content['product_id'] !== $cartItem['product_id'] ) {				continue;			}			$product = $cart_content['data'];			// Exclude variations that are already on sale			if ( $product && $product->is_on_sale() ) {				continue;			}			$count += (int) $cart_content['quantity'];		}		return $count;	}, 10, 2 );
       ```
   
 *  Thread Starter [PetrP](https://wordpress.org/support/users/petrp/)
 * (@petrp)
 * [4 months ago](https://wordpress.org/support/topic/calculation-logic-4/#post-18813272)
 * perfect, thank you so much, Mykola! Have a great weekend
 *  Plugin Author [Mykola Lukin](https://wordpress.org/support/users/bycrik/)
 * (@bycrik)
 * [4 months ago](https://wordpress.org/support/topic/calculation-logic-4/#post-18814416)
 * Hello [@petrp](https://wordpress.org/support/users/petrp/),
 * Thanks for confirming!
 *  I’d really appreciate it if you could leave a rating for the plugin.
 * Thank you!
 *  Thread Starter [PetrP](https://wordpress.org/support/users/petrp/)
 * (@petrp)
 * [3 months, 4 weeks ago](https://wordpress.org/support/topic/calculation-logic-4/#post-18816354)
 * you got it 🙂

Viewing 6 replies - 1 through 6 (of 6 total)

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcalculation-logic-4%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/tier-pricing-table/assets/icon-256x256.gif?rev=3025448)
 * [Tiered Pricing Table for WooCommerce](https://wordpress.org/plugins/tier-pricing-table/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tier-pricing-table/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tier-pricing-table/)
 * [Active Topics](https://wordpress.org/support/plugin/tier-pricing-table/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tier-pricing-table/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tier-pricing-table/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [PetrP](https://wordpress.org/support/users/petrp/)
 * Last activity: [3 months, 4 weeks ago](https://wordpress.org/support/topic/calculation-logic-4/#post-18816354)
 * Status: resolved