You've already forked wc-tier-and-package-prices
Release version 1.1.1 - Cart quantity field hiding
Enhanced package quantity restriction enforcement by hiding the cart quantity input field when restrictions are enabled. This prevents customers from modifying quantities in the cart to bypass package restrictions. Changes: - Added cart quantity input hiding for restricted products - Implemented woocommerce_cart_item_quantity filter hook - Created maybe_hide_cart_quantity_input() method in WC_TPP_Cart - Fixed cart quantity bypass vulnerability - Cart displays quantity as read-only text for restricted products 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@ class WC_TPP_Cart {
|
||||
add_filter('woocommerce_cart_item_price', array($this, 'display_cart_item_price'), 10, 3);
|
||||
add_filter('woocommerce_cart_item_subtotal', array($this, 'display_cart_item_subtotal'), 10, 3);
|
||||
add_filter('woocommerce_add_to_cart_validation', array($this, 'validate_package_quantity'), 10, 3);
|
||||
add_filter('woocommerce_cart_item_quantity', array($this, 'maybe_hide_cart_quantity_input'), 10, 3);
|
||||
}
|
||||
|
||||
public function apply_tier_package_pricing($cart) {
|
||||
@@ -137,6 +138,24 @@ class WC_TPP_Cart {
|
||||
|
||||
return $passed;
|
||||
}
|
||||
|
||||
public function maybe_hide_cart_quantity_input($product_quantity, $cart_item_key, $cart_item) {
|
||||
$product_id = $cart_item['product_id'];
|
||||
|
||||
// Check if restriction is enabled globally or for this product
|
||||
$global_restrict = get_option('wc_tpp_restrict_package_quantities', 'no') === 'yes';
|
||||
$product_restrict = get_post_meta($product_id, '_wc_tpp_restrict_to_packages', true) === 'yes';
|
||||
|
||||
// Get packages for this product
|
||||
$packages = get_post_meta($product_id, '_wc_tpp_packages', true);
|
||||
|
||||
// If restriction is enabled and packages exist, show quantity as text only
|
||||
if (($global_restrict || $product_restrict) && !empty($packages)) {
|
||||
return sprintf('<span class="wc-tpp-cart-quantity">%s</span>', $cart_item['quantity']);
|
||||
}
|
||||
|
||||
return $product_quantity;
|
||||
}
|
||||
}
|
||||
|
||||
new WC_TPP_Cart();
|
||||
|
||||
Reference in New Issue
Block a user