Conversation
supportWhen you have a minimum category quantity restriction enabled, you can end up with the coupon being applied when it should not be. This is because of the way this plugin ( and woocommerce in general ) is handling product category look ups. In class-wt-smart-coupon-resistriction-public.php, around line 673, this plugin is accessing the product categories of a given item: $product_cats = wc_get_product_cat_ids( $item[‘product_id’] ); In the next line there is an array_intersect to determine if any of those categories are in the categories picked for this restriction. The PROBLEM is that, at least currently, the woocommerce function wc_get_product_cat_ids will return duplicate category ID’s if there is a parent/child selection on the product. For instance if you have a Cheese category and a Cheddar child category with both selected, this wc_get_product_cat_ids call will return an array of 3 items ( cheese, cheese, cheddar ). THEN, the array_intersect that this plugin is calling ends up having 2 matching categories instead of 1. This matters because it creates a fake double item count to determine if there are enough items in the cart to warrant the coupon. I don’t know if this is intended for the woocommerce wc_get_product_cat_ids function, but if this plugin simply adds an array_unique() wrap around the $product_cats call then the situation should resolve itself. This took a lot of debugging to pinpoint and ended up making it so multiple orders were placed on our store with coupon discounts that should not have been. Please patch this at your earliest convenience.
Hi @nkals722 , Thank you again for taking the time to report this in such detail — we really appreciate your effort. We were able to replicate the issue on our end exactly as you described. It appears the duplicate category IDs returned by wc_get_product_cat_ids() are indeed causing the category quantity check to miscount when both parent and child categories are assigned. We’ve escalated this to our development team, and we’re currently reviewing the best approach to resolve it. We’ll include this in the upcoming release of the plugin to handle it properly. Thanks again for helping us identify this — your feedback is incredibly valuable.
https://c.tenor.com/F8PHD4TebUkAAAAd/tenor.gif
Hi @nkals722 , Thank you again for taking the time to report this in such detail — we really appreciate your effort. We were able to replicate the issue on our end exactly as you described. It appears the duplicate category IDs returned by wc_get_product_cat_ids() are indeed causing the category quantity check to miscount when both parent and child categories are assigned. We’ve escalated this to our development team, and we’re currently reviewing the best approach to resolve it. We’ll include this in the upcoming release of the plugin to handle it properly. Thanks again for helping us identify this — your feedback is incredibly valuable.
https://c.tenor.com/F8PHD4TebUkAAAAd/tenor.gif