• Resolved PetrP

    (@petrp)


    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

    (@bycrik)

    Hello @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:

    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

    (@petrp)

    Hi, thank you for the effort, but unfortunately it throws php errors.
    I have PHP 8.5 latest WP & WC.

    Plugin Author Mykola Lukin

    (@bycrik)

    Hello @petrp,

    Sorry, please find the updated code below:

    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

    (@petrp)

    perfect, thank you so much, Mykola! Have a great weekend

    Plugin Author Mykola Lukin

    (@bycrik)

    Hello @petrp,

    Thanks for confirming!

    I’d really appreciate it if you could leave a rating for the plugin.

    Thank you!

    Thread Starter PetrP

    (@petrp)

    you got it 🙂

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

You must be logged in to reply to this topic.