Created
December 3, 2025 14:39
-
-
Save shameemreza/e7231a21b055a9f51408ba8e218e1692 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Disable Min/Max "Group of" quantity rules for bundled products. | |
| * This allows bundled items to have a quantity of 1 even when the | |
| * standalone product has a "Group of 6" rule. | |
| * | |
| * @author Shameem Reza | |
| */ | |
| // Product Bundles side - disable Group of for bundled item calculations. | |
| add_filter( 'woocommerce_bundled_item_group_of_quantity', '__return_zero', 999 ); | |
| // Min/Max Quantities cart validation - disable Group of for bundled cart items. | |
| add_filter( 'wc_min_max_quantity_group_of_quantity', 'wcsubs_disable_group_of_for_bundled_items', 999, 4 ); | |
| /** | |
| * Disable Group of quantity for bundled cart items. | |
| * | |
| * @param int $group_of_quantity The Group of quantity. | |
| * @param int $product_id The product ID. | |
| * @param string $cart_item_key The cart item key. | |
| * @param array $cart_item The cart item data. | |
| * @return int | |
| */ | |
| function wcsubs_disable_group_of_for_bundled_items( $group_of_quantity, $product_id, $cart_item_key, $cart_item ) { | |
| if ( is_array( $cart_item ) && function_exists( 'wc_pb_is_bundled_cart_item' ) && wc_pb_is_bundled_cart_item( $cart_item ) ) { | |
| return 0; | |
| } | |
| return $group_of_quantity; | |
| } | |
| // Store API level - override quantity limits for bundled cart items. | |
| add_filter( 'woocommerce_store_api_product_quantity_minimum', 'wcsubs_fix_bundled_item_store_api_min', 999, 3 ); | |
| add_filter( 'woocommerce_store_api_product_quantity_maximum', 'wcsubs_fix_bundled_item_store_api_max', 999, 3 ); | |
| add_filter( 'woocommerce_store_api_product_quantity_multiple_of', 'wcsubs_fix_bundled_item_store_api_step', 999, 3 ); | |
| /** | |
| * Fix minimum quantity for bundled items in Store API. | |
| * | |
| * @param int $value The minimum quantity. | |
| * @param WC_Product $product The product object. | |
| * @param array|null $cart_item The cart item data. | |
| * @return int | |
| */ | |
| function wcsubs_fix_bundled_item_store_api_min( $value, $product, $cart_item ) { | |
| if ( wcsubs_is_bundled_cart_item( $cart_item ) ) { | |
| return 1; | |
| } | |
| return $value; | |
| } | |
| /** | |
| * Fix maximum quantity for bundled items in Store API. | |
| * | |
| * @param int $value The maximum quantity. | |
| * @param WC_Product $product The product object. | |
| * @param array|null $cart_item The cart item data. | |
| * @return int | |
| */ | |
| function wcsubs_fix_bundled_item_store_api_max( $value, $product, $cart_item ) { | |
| if ( wcsubs_is_bundled_cart_item( $cart_item ) ) { | |
| return 9999; | |
| } | |
| return $value; | |
| } | |
| /** | |
| * Fix step/multiple_of quantity for bundled items in Store API. | |
| * | |
| * @param int $value The step quantity. | |
| * @param WC_Product $product The product object. | |
| * @param array|null $cart_item The cart item data. | |
| * @return int | |
| */ | |
| function wcsubs_fix_bundled_item_store_api_step( $value, $product, $cart_item ) { | |
| if ( wcsubs_is_bundled_cart_item( $cart_item ) ) { | |
| return 1; | |
| } | |
| return $value; | |
| } | |
| /** | |
| * Helper function to check if cart item is a bundled item. | |
| * | |
| * @param array|null $cart_item The cart item data. | |
| * @return bool | |
| */ | |
| function wcsubs_is_bundled_cart_item( $cart_item ) { | |
| if ( ! is_array( $cart_item ) ) { | |
| return false; | |
| } | |
| if ( function_exists( 'wc_pb_is_bundled_cart_item' ) && wc_pb_is_bundled_cart_item( $cart_item ) ) { | |
| return true; | |
| } | |
| // Fallback check. | |
| if ( isset( $cart_item['bundled_by'] ) || isset( $cart_item['bundled_item_id'] ) ) { | |
| return true; | |
| } | |
| return false; | |
| } |
Author
shameemreza
commented
Dec 3, 2025

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment