Okay
  Public Ticket #4510011
Tiered discount should calculate on combined quantity of a product group (not per individual product)
Open

Comments

  •  2
    Vladislav started the conversation

    Hello B2BKing team,

    I’m trying to configure tiered pricing so that the discount is applied based on the combined quantity of all items in a product group/category, not per individual product.

    Goal (expected behavior):
    If a customer buys multiple different products from the same group (e.g., Group A), the total quantity across that group should count toward the tier.
    Example tiers:

    • 3+ units (any mix from Group A) → 5% off all Group A items in the cart

    • 6+ units (any mix from Group A) → 10% off all Group A items in the cart

    Current behavior (issue):
    Tiered discount is calculated per product. So if Group A has 30 products, the rule only triggers when the quantity of a single product reaches the tier, instead of using the sum of quantities of all products in Group A within the cart.

    How I configured it:

    • Rule Type: Tiered Price (Price by Quantity)

    • Applies to: Product Group / Category (not a single product)

    • Applies to who: Specific B2B group (hairdressers) and/or All users

    • Tiers: e.g., 3→5%, 6→10%, 12→15%

    • I need the rule to sum quantities across the selected group/category in the cart.

    What I need:

    1. Either a built-in option (e.g., “Calculate tiers based on combined quantity of selected group/category in cart”), or

    2. A code snippet / filter / hook I can add to make tier thresholds evaluate against the aggregated quantity of all items in the chosen group/category.

    Illustrative example:
    Cart has:

    • Product A (Group A): qty 1

    • Product B (Group A): qty 2
      Total for Group A = 3 → Should trigger the 3+ tier and apply 5% to both A and B.
      Currently, discount does not trigger unless a single product reaches qty 3.

    If you can provide a code snippet or point me to the correct setting to make tiered rules aggregate quantities by group/category across the cart, that would be perfect. Thank you!

  •  2
    Vladislav replied

    We need Tiered Price (Price by Quantity) rules to calculate tiers based on the combined cart quantity of items inside the selected product group/category, and then apply the discount to all items from that selected group—not per individual product.

    Target group (what we want the rule to apply to)
    • Product group/category: e.g., “I.C.O.N. Ecotech” (category ID 151)
      (This is just an example. We want this to work for any category or product group we select in the rule.)

    • Applies to who: our B2B customer group “Hairdressers” (and optionally All users for testing).

    Expected behavior

    If a customer buys different products from the selected group/category, the sum of quantities across that group should determine the tier, and the discount should apply to all items from that group in the cart.

    Example tiers:

    • 3+ (any mix from the selected group) → 5% off all those items

    • 6+ (any mix) → 10% off

    • 12+ (any mix) → 15% off

    Illustration:
    Cart = Product A (Group) qty 1 + Product B (Group) qty 2 → total 3 in the selected group → should trigger 3+ tier and apply 5% to both A and B.

    Current behavior (issue)

    Tiers evaluate per product, so the rule only triggers when a single product reaches the threshold, instead of using the aggregate quantity of all items in the selected group/category.

    Our configuration
    • Dynamic Rules → Rule Type: Tiered Price (Price by Quantity)

    • Applies to: Product Category / Product Group (not single product)

    • Applies to who: Hairdressers (B2B group) and/or All users

    • Tiers: e.g., 3→5%, 6→10%, 12→15%

    What we need
    • A built-in option (e.g., “Calculate tiers based on combined quantity of the selected group/category in cart”), or

    • An official code snippet / filter / hook to aggregate quantities by the rule’s selected scope (category or product group, including child categories) and apply the resulting tier to all matching items in the cart.

    What we tried (for your reference)

    We enabled cart-wide tier calculation and tested a custom filter to sum quantities in one category (ID 151) including its children. It worked earlier for a single category, but after further adjustments it stopped applying in cart. We would prefer an official, supported approach that works whenever we choose any category/product group in the rule.

    Questions
    1. Is there a built-in way for Tiered Price rules to aggregate by the selected group/category across the cart (not per product)?

    2. If not, could you share an official snippet that sums quantities by the rule’s scope (selected category/group), including children, and applies the tier to all items in that scope?

    3. Do all items need to share the exact same rule for aggregation to work, or can multiple Tiered rules target the same scope and still aggregate?

    4. Any known limitations, hook order, or caching considerations we should follow?

    Access for faster troubleshooting

    We can provide temporary WP admin/staging access if helpful. Please let us know the safest way to share credentials.

    Thanks a lot for your guidance!

  •   Vladislav replied privately
  •  2,593
    WebWizards replied

    Hi Vladislav,

    Thanks for explaining this in detail.

    I understand what you mean. B2BKing does not yet support this officially: it's something we have been looking at adding but does not exist as a built-in feature yet.

    What I can do for you is help with a code snippet that will let you hardcode product groups directly within the snippet. Then whenever products from that group are in the cart, it will use the combined quantity of their group to calculate the tier. This cannot be done officially or with rules for now, only via code through this snippet.

     

    Please use this snippet: https://pastecode.io/s/7d4hosvu

    At the beginning of the snippet you can configure groups of categories and products that will be counted together. There are 4 group examples there, just delete what you don't need, they're just for demonstration.

     

    The snippet can be added to functions.php of your theme or any code snippets plugin.

    Let me know if you run into any issues,

    Kind regards,
    Stefan

  •  2
    Vladislav replied

    thank you its working

  •  2
    Vladislav replied

    its not working 

    Right now the plugin calculates discounts based on the total cart quantity, regardless of which products are in the cart. In the rule UI we only see options like “Cart quantity” or “Cart value,” but there is no option to count only the quantity of the products targeted by the rule (e.g., selected products/categories/attributes).

    What we need:
    An option/setting so that the threshold for tiered/quantity discounts is calculated only from the quantity of the products included in that specific rule (not from unrelated items in the cart).

    Example:

    • Rule targets Product A (or Category X).

    • Cart contains 1× Product A and 5× Product B (not targeted by the rule).

    • Currently, the rule triggers because total cart quantity = 6.

    • Expected: the rule should only count qty of Product A = 1, so the threshold should not be met.

    Please advise if there is a built-in setting or recommended filter/action to enable “count matched products only” behavior for tiered/quantity rules. If not available, could you provide the official snippet or guidance to achieve this?

    Thank you!


  •  2,593
    WebWizards replied

    Hi Vladislav,

    The snippet I shared is specifically designed for tiered pricing ( https://woocommerce-b2b-plugin.com/docs/b2bking-tiered-pricing-setup-auto-generated-tiered-pricing-table/ )

    This snippet does not apply to dynamic rules or other plugin systems - it's exclusively for the tiered pricing functionality.

     

    Regarding rule conditions:
    In B2BKing's dynamic rules, conditions like "Cart quantity" and "Cart value" apply based on the total cart.

    There are also conditions for "Category quantity" and "Product quantity," but those only apply if you select individual products or individual categories in the rule.

     

    I've also replied in your other ticket regarding a potential custom snippet for discounts based on attributes - please check that as well.

     

    Kind regards,
    Stefan

  •  2
    Vladislav replied

    Hi Stefan,

    Quick update — the attribute option works on our side, thanks.
    However, when we add this filter to expose the attribute in Dynamic Rules:

    add_filter('b2bking_dynamic_rules_taxonomy_option', function($taxonomy){    return 'pa_talpa';
    }, 10, 1);
    

    the UI switches to the attribute mode and the other rule conditions disappear, e.g.:

    • Category / Group quantity

    • Product quantity (within the selected scope)

    In practice, after enabling the attribute option, we no longer see the choices that let us count only the quantity of the selected group/category (or selected products). The rule falls back to “Cart quantity/value” (whole cart), which is not what we need.

    What we need:

    1. Keep the attribute (pa_talpa) selection available without losing the conditions to count quantity for selected groups/categories/products only; or

    2. Provide an official snippet that counts only the combined quantity of items with a specific attribute value in the cart (e.g., pa_talpa = 1000 ml), applies the rule only when the min qty is reached, and does not include unrelated items.

    Important pricing base: the discount should be calculated from the regular (B2C) price, not from any B2B discounted price (to avoid double-discounting).

    If option (1) is not currently possible, we’re happy to proceed with option (2). Please share the snippet (preferably hooked in woocommerce_cart_calculate_fees) with:

    • Attribute taxonomy: pa_talpa

    • Values handled separately (e.g., 1000 ml, 3000 ml, 5000 ml)

    • Threshold example: ≥ 3 for a given attribute value

    • Discount applied only to matching items; base = regular price; no stacking with other rules

    Thanks a lot!
    Vladislav

  •  2,593
    WebWizards replied

    Hi Vladislav,

    The conditions you mentioned (like "Category quantity" or "Product quantity") are fixed to work with specific categories or products selected in the rule – they cannot be applied to attributes or custom taxonomies in the same way.

    We can provide a custom code snippet that applies a discount based on `pa_talpa` quantity with a minimum threshold. However, it would stack with other discounts. I don't have a way to make it invalidate other B2BKing discounts automatically.

     

    Given this limitation, I'm not entirely sure what the best approach would be for your setup.

    You could also consider using a dedicated discount/pricing rules plugin that may offer more flexibility for attribute-based quantity rules. In that case, you could disable all of B2BKing's pricing code to avoid conflicts via B2BKing → Settings → Other → Components.

     

    Kind regards,
    Stefan

  •  2
    Vladislav replied

    Hi,

    Thank you for the information and your assistance. Since it’s currently not possible to achieve the discount logic we need with your plugin, we’ve decided to test an alternative solution. We are now trying the Flycart plugin, and their discount system works exactly the way we require.

    I would recommend taking a look at how their system is built — it’s very similar to yours, but certain scenarios are handled more efficiently and we haven’t encountered as many bugs or issues as we did here.

    Thank you again for your time.