diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 2e98458..fd19015 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -8,7 +8,12 @@ "Bash(composer init:*)", "Bash(composer install:*)", "Bash(composer update:*)", - "Bash(git add:*)" + "Bash(git add:*)", + "Bash(git commit -m \"$\\(cat <<''EOF''\nRelease version 1.1.0 - Package quantity restriction feature\n\nAdded comprehensive package quantity restriction functionality that allows\nlimiting product purchases to predefined package sizes only.\n\nFeatures:\n- Global setting to enable package quantity restrictions\n- Per-product override for quantity restrictions\n- Automatic hiding of quantity input field when restricted\n- Frontend validation with package selection UI\n- Server-side cart validation\n- User-friendly error messages\n- Complete translations for all supported languages\n\nšŸ¤– Generated with [Claude Code]\\(https://claude.com/claude-code\\)\n\nCo-Authored-By: Claude Sonnet 4.5 \nEOF\n\\)\")", + "Bash(git tag:*)", + "Bash(rsync:*)", + "Bash(zip -r:*)", + "Bash(cat:*)" ] } } diff --git a/CHANGELOG.md b/CHANGELOG.md index 85109c7..f22a90c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,24 @@ All notable changes to WooCommerce Tier and Package Prices will be documented in The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1.1] - 2025-12-21 + +### Added +- Cart quantity field hiding when package restriction is enabled +- Automatic read-only quantity display in cart for restricted products + +### Changed +- Cart quantity input replaced with plain text when restrictions apply +- Enhanced cart display to prevent quantity modification for restricted products + +### Fixed +- Cart quantity bypass vulnerability for package-restricted products + +### Technical +- Added `maybe_hide_cart_quantity_input()` method in WC_TPP_Cart class +- Extended `woocommerce_cart_item_quantity` filter hook +- CSS class `wc-tpp-cart-quantity` for styled quantity display + ## [1.1.0] - 2025-12-21 ### Added diff --git a/composer.json b/composer.json index ac92b86..277df76 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "magdev/wc-tier-package-prices", "description": "WooCommerce plugin for tier pricing and package prices with Twig templates", - "version": "1.1.0", + "version": "1.1.1", "type": "wordpress-plugin", "license": "GPL-2.0-or-later", "authors": [ diff --git a/includes/class-wc-tpp-cart.php b/includes/class-wc-tpp-cart.php index ffeaf59..a71b71f 100644 --- a/includes/class-wc-tpp-cart.php +++ b/includes/class-wc-tpp-cart.php @@ -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('%s', $cart_item['quantity']); + } + + return $product_quantity; + } } new WC_TPP_Cart(); diff --git a/languages/wc-tier-package-prices-de_CH_informal.po b/languages/wc-tier-package-prices-de_CH_informal.po index 8c9e35c..6f367b2 100644 --- a/languages/wc-tier-package-prices-de_CH_informal.po +++ b/languages/wc-tier-package-prices-de_CH_informal.po @@ -3,7 +3,7 @@ # This file is distributed under the GPL v2 or later. msgid "" msgstr "" -"Project-Id-Version: WooCommerce Tier and Package Prices 1.1.0\n" +"Project-Id-Version: WooCommerce Tier and Package Prices 1.1.1\n" "Report-Msgid-Bugs-To: https://src.bundespruefstelle.ch/wc-tier-package-prices\n" "POT-Creation-Date: 2025-12-21 00:00+0000\n" "PO-Revision-Date: 2025-12-21 00:00+0000\n" diff --git a/languages/wc-tier-package-prices-de_DE.po b/languages/wc-tier-package-prices-de_DE.po index 7f1da92..1aa1e65 100644 --- a/languages/wc-tier-package-prices-de_DE.po +++ b/languages/wc-tier-package-prices-de_DE.po @@ -3,7 +3,7 @@ # This file is distributed under the GPL v2 or later. msgid "" msgstr "" -"Project-Id-Version: WooCommerce Tier and Package Prices 1.1.0\n" +"Project-Id-Version: WooCommerce Tier and Package Prices 1.1.1\n" "Report-Msgid-Bugs-To: https://src.bundespruefstelle.ch/wc-tier-package-prices\n" "POT-Creation-Date: 2025-12-21 00:00+0000\n" "PO-Revision-Date: 2025-12-21 00:00+0000\n" diff --git a/languages/wc-tier-package-prices-en_US.po b/languages/wc-tier-package-prices-en_US.po index be37bb9..e7377f9 100644 --- a/languages/wc-tier-package-prices-en_US.po +++ b/languages/wc-tier-package-prices-en_US.po @@ -3,7 +3,7 @@ # This file is distributed under the GPL v2 or later. msgid "" msgstr "" -"Project-Id-Version: WooCommerce Tier and Package Prices 1.1.0\n" +"Project-Id-Version: WooCommerce Tier and Package Prices 1.1.1\n" "Report-Msgid-Bugs-To: https://src.bundespruefstelle.ch/wc-tier-package-prices\n" "POT-Creation-Date: 2025-12-21 00:00+0000\n" "PO-Revision-Date: 2025-12-21 00:00+0000\n" diff --git a/languages/wc-tier-package-prices.pot b/languages/wc-tier-package-prices.pot index 30438a7..8f58d1a 100644 --- a/languages/wc-tier-package-prices.pot +++ b/languages/wc-tier-package-prices.pot @@ -2,7 +2,7 @@ # This file is distributed under the GPL v2 or later. msgid "" msgstr "" -"Project-Id-Version: WooCommerce Tier and Package Prices 1.1.0\n" +"Project-Id-Version: WooCommerce Tier and Package Prices 1.1.1\n" "Report-Msgid-Bugs-To: https://src.bundespruefstelle.ch/wc-tier-package-prices\n" "POT-Creation-Date: 2025-12-21 00:00+0000\n" "MIME-Version: 1.0\n" diff --git a/releases/RELEASE-INFO-1.1.0.md b/releases/RELEASE-INFO-1.1.0.md new file mode 100644 index 0000000..48082c1 --- /dev/null +++ b/releases/RELEASE-INFO-1.1.0.md @@ -0,0 +1,345 @@ +# WooCommerce Tier and Package Prices - Release 1.1.0 + +**Release Date:** December 21, 2025 +**Version:** 1.1.0 +**Package Size:** 387 KB +**Git Tag:** v1.1.0 + +## Download + +**File:** `wc-tier-and-package-prices-1.1.0.zip` + +### Checksums + +**SHA256:** +``` +da6b462f3dc297b282ed0da258b78fd9f2f82f3e76289c4c8fadd1ac9e02c55b +``` + +**MD5:** +``` +ef68125c54b0c10f04ba82d48a98b4aa +``` + +## What's New in 1.1.0 + +### Major Features +- ✨ **Package Quantity Restriction** - NEW + - Limit product purchases to predefined package sizes only + - Perfect for bulk-only sales, sample packs, or fixed bundle quantities + - Global and per-product configuration options + +### New Settings +- šŸŒ **Global Restriction Setting** + - Enable quantity restrictions site-wide + - Located in: WooCommerce > Settings > Tier & Package Prices + - Description: "Limit quantities to defined package sizes only" + +- šŸ“¦ **Per-Product Restriction Setting** + - Override global setting on individual products + - Located in: Product Edit > Package Pricing section + - Checkbox: "Restrict to Package Quantities" + +### Frontend Enhancements +- šŸŽØ **Enhanced Package Selection UI** + - Automatic quantity field hiding when restriction is enabled + - Clear notice: "Choose a package size below" + - Visual package selection with highlighted states + - Responsive package selection buttons + +- āœ… **Client-Side Validation** + - JavaScript prevents form submission without package selection + - Alert message guides users to select a package + - Real-time visual feedback on selection + +### Backend Validation +- šŸ›”ļø **Server-Side Cart Validation** + - Validates quantity matches defined packages + - Prevents manual quantity manipulation + - User-friendly error messages + - Example: "The quantity 15 is not available for Product Name. Please choose from the available package sizes: 10, 20, 50" + +### Technical Improvements +- New method: `WC_TPP_Cart::validate_package_quantity()` +- New method: `WC_TPP_Frontend::maybe_hide_quantity_input()` +- Enhanced `woocommerce_add_to_cart_validation` filter integration +- Added `wc-tpp-restricted-mode` CSS class +- Added `wc-tpp-package-selectable` CSS class for styling +- New product meta key: `_wc_tpp_restrict_to_packages` +- New global option: `wc_tpp_restrict_package_quantities` + +### Translations +- Added 7 new translatable strings +- Updated all language files (en_US, de_DE, de_CH_informal) +- All .mo files recompiled with new strings + +## Installation + +1. Download the ZIP file: `wc-tier-and-package-prices-1.1.0.zip` +2. Log in to your WordPress admin panel +3. Navigate to **Plugins > Add New > Upload Plugin** +4. Choose the downloaded ZIP file +5. Click **Install Now** +6. After installation, click **Activate Plugin** +7. Go to **WooCommerce > Settings > Tier & Package Prices** to configure + +### Upgrade from 1.0.x + +This is a **minor version** update with new features. No data migration needed. + +**Steps:** +1. Deactivate the current version +2. Upload and activate version 1.1.0 +3. All existing settings and data will be automatically preserved +4. Review new restriction settings if desired + +### Upgrade from 1.0.2 + +No breaking changes. Safe to upgrade directly. New restriction feature is disabled by default. + +### Requirements + +- **WordPress:** 6.0 or higher +- **PHP:** 7.4 or higher +- **WooCommerce:** 8.0 or higher + +## New Strings Translation Reference + +All new strings in this release: + +### Settings Page +1. "Restrict to Package Quantities" - Checkbox label +2. "Limit quantities to defined package sizes only" - Checkbox description +3. "When enabled, customers can only purchase..." - Tooltip text + +### Product Meta Box +4. "Restrict to Package Quantities" - Checkbox label (same as above) +5. "Only allow quantities defined in packages above" - Tooltip text + +### Frontend Display +6. "Choose a package size below" - User notice in restricted mode + +### Cart Validation +7. "this product" - Fallback product name +8. "The quantity %1$d is not available for %2$s..." - Error message template + +## Use Cases + +### Bulk-Only Sales +Enable restriction globally to sell products only in bulk quantities. + +**Example:** +- Package 1: 100 units at $500 +- Package 2: 250 units at $1,100 +- Package 3: 500 units at $2,000 + +Customers can only purchase these exact quantities. + +### Sample Packs +Create fixed sample packs with no custom quantities. + +**Example:** +- Starter Pack: 10 items +- Trial Pack: 25 items +- Full Pack: 50 items + +### Promotional Bundles +Offer promotional pricing only for specific bundle sizes. + +**Example:** +- Holiday Bundle: 12 units (seasonal pricing) +- Party Pack: 24 units (bulk discount) +- Wholesale Bundle: 100 units (wholesale pricing) + +## Configuration Examples + +### Example 1: Site-Wide Restriction + +**Scenario:** All products should only be sold in packages + +**Configuration:** +1. Go to WooCommerce > Settings > Tier & Package Prices +2. Check "Restrict to Package Quantities" +3. Save changes +4. Configure package sizes for each product + +**Result:** All products with packages defined will enforce quantity restrictions + +### Example 2: Per-Product Restriction + +**Scenario:** Only specific products need quantity restrictions + +**Configuration:** +1. Leave global setting unchecked +2. Edit the specific product +3. Scroll to Package Pricing section +4. Check "Restrict to Package Quantities" +5. Update product + +**Result:** Only that product enforces restrictions + +### Example 3: Mixed Approach + +**Scenario:** Most products are restricted, but some allow custom quantities + +**Configuration:** +1. Enable global restriction +2. For products that should allow custom quantities, simply don't define any packages +3. Products without packages defined won't show restrictions + +## Feature Compatibility + +### Works With +- āœ… WooCommerce 8.0 - 10.0 +- āœ… WordPress 6.0+ +- āœ… HPOS (High-Performance Order Storage) +- āœ… All WooCommerce themes +- āœ… Tier pricing (can use both features together) +- āœ… Package pricing (required for restriction) +- āœ… All pricing table display positions + +### Requirements for Restriction Feature +- Product must have at least one package defined +- Either global or per-product restriction must be enabled +- Package pricing must be enabled in settings + +## Package Contents + +The installation package includes all files from version 1.0.2 plus: + +### Modified Files +- `wc-tier-and-package-prices.php` - Version updated to 1.1.0 +- `composer.json` - Version updated to 1.1.0 +- `CHANGELOG.md` - Added v1.1.0 section +- `includes/class-wc-tpp-settings.php` - Added restriction setting +- `includes/class-wc-tpp-product-meta.php` - Added per-product checkbox +- `includes/class-wc-tpp-frontend.php` - Added quantity hiding logic +- `includes/class-wc-tpp-cart.php` - Added validation method +- `assets/js/frontend.js` - Added restricted mode handling +- `templates/frontend/package-pricing-display.twig` - Added restriction notice +- `templates/frontend/pricing-table.twig` - Pass restriction flag +- All translation files (.po/.mo) - Updated with new strings + +### Complete Directory Structure +``` +wc-tier-and-package-prices/ +ā”œā”€ā”€ assets/ +│ ā”œā”€ā”€ css/ +│ │ ā”œā”€ā”€ admin.css +│ │ └── frontend.css +│ └── js/ +│ ā”œā”€ā”€ admin.js +│ └── frontend.js (UPDATED) +ā”œā”€ā”€ includes/ +│ ā”œā”€ā”€ class-wc-tpp-admin.php +│ ā”œā”€ā”€ class-wc-tpp-cart.php (UPDATED) +│ ā”œā”€ā”€ class-wc-tpp-frontend.php (UPDATED) +│ ā”œā”€ā”€ class-wc-tpp-product-meta.php (UPDATED) +│ ā”œā”€ā”€ class-wc-tpp-settings.php (UPDATED) +│ └── class-wc-tpp-template-loader.php +ā”œā”€ā”€ languages/ (ALL UPDATED) +│ ā”œā”€ā”€ wc-tier-package-prices-de_CH_informal.po/mo +│ ā”œā”€ā”€ wc-tier-package-prices-de_DE.po/mo +│ ā”œā”€ā”€ wc-tier-package-prices-en_US.po/mo +│ └── wc-tier-package-prices.pot +ā”œā”€ā”€ templates/ +│ ā”œā”€ā”€ admin/ +│ │ ā”œā”€ā”€ package-row.twig +│ │ └── tier-row.twig +│ └── frontend/ +│ ā”œā”€ā”€ package-pricing-display.twig (UPDATED) +│ ā”œā”€ā”€ pricing-table.twig (UPDATED) +│ └── tier-pricing-table.twig +ā”œā”€ā”€ vendor/ (Twig v3.22.2) +ā”œā”€ā”€ CHANGELOG.md (UPDATED) +ā”œā”€ā”€ composer.json (UPDATED) +└── wc-tier-and-package-prices.php (UPDATED) +``` + +## Features (Complete List) + +### Tier Pricing +- āœ… Quantity-based discount tiers +- āœ… Automatic price calculation +- āœ… Volume discount display + +### Package Pricing +- āœ… Fixed-price bundles +- āœ… Custom package labels +- āœ… Multiple package options per product +- āœ… **NEW:** Quantity restriction to packages only + +### Admin Features +- āœ… WooCommerce Settings integration +- āœ… Easy-to-use product meta boxes +- āœ… Configurable display positions +- āœ… Native WooCommerce UI +- āœ… **NEW:** Global restriction setting +- āœ… **NEW:** Per-product restriction override + +### Frontend Features +- āœ… Beautiful pricing tables (Twig templates) +- āœ… Real-time cart updates +- āœ… Responsive design +- āœ… 3 languages supported +- āœ… **NEW:** Package-only selection mode +- āœ… **NEW:** Automatic quantity field hiding +- āœ… **NEW:** Visual package selection + +### Validation & Security +- āœ… **NEW:** Client-side JavaScript validation +- āœ… **NEW:** Server-side cart validation +- āœ… **NEW:** User-friendly error messages +- āœ… WooCommerce HPOS compatible + +## Breaking Changes + +**None.** This release is fully backward compatible. + +The new restriction feature is disabled by default and must be explicitly enabled. + +## Migration Notes + +### From 1.0.2 +- No migration needed +- New settings appear automatically in admin +- Feature is disabled by default + +### Settings Location +All settings remain in: **WooCommerce > Settings > Tier & Package Prices** + +### Data Preservation +- All existing tier pricing data preserved +- All existing package pricing data preserved +- All product meta data preserved +- No database changes required + +## Known Limitations + +### Current Version +1. Restriction only works when packages are defined +2. Cannot restrict to tier quantities (only packages) +3. Restriction applies to entire product (no variation-level control) + +### Future Enhancements +These features may be added in future versions: +- Variation-level restriction control +- Restrict to tier quantities option +- Minimum/maximum package selection limits + +## Support + +- **Documentation:** See README.md and CHANGELOG.md +- **Previous Release:** See RELEASE-INFO-1.0.2.md +- **Issues:** https://src.bundespruefstelle.ch/wc-tier-package-prices/issues +- **Author:** Marco Graetsch + +## License + +GPL v2 or later - https://www.gnu.org/licenses/gpl-2.0.html + +--- + +**Production Ready:** This package includes optimized autoloader and no development dependencies. + +**What's Next:** Version 1.1.0 completes the package restriction feature set. Future versions may add variation-level controls and tier quantity restrictions. diff --git a/releases/wc-tier-and-package-prices-1.1.0.zip b/releases/wc-tier-and-package-prices-1.1.0.zip new file mode 100644 index 0000000..834d77a Binary files /dev/null and b/releases/wc-tier-and-package-prices-1.1.0.zip differ diff --git a/releases/wc-tier-and-package-prices-1.1.0.zip.md5 b/releases/wc-tier-and-package-prices-1.1.0.zip.md5 new file mode 100644 index 0000000..b731f2a --- /dev/null +++ b/releases/wc-tier-and-package-prices-1.1.0.zip.md5 @@ -0,0 +1 @@ +ef68125c54b0c10f04ba82d48a98b4aa wc-tier-and-package-prices-1.1.0.zip diff --git a/releases/wc-tier-and-package-prices-1.1.0.zip.sha256 b/releases/wc-tier-and-package-prices-1.1.0.zip.sha256 new file mode 100644 index 0000000..2c8c9f8 --- /dev/null +++ b/releases/wc-tier-and-package-prices-1.1.0.zip.sha256 @@ -0,0 +1 @@ +da6b462f3dc297b282ed0da258b78fd9f2f82f3e76289c4c8fadd1ac9e02c55b wc-tier-and-package-prices-1.1.0.zip diff --git a/wc-tier-and-package-prices.php b/wc-tier-and-package-prices.php index 06edf97..1f70ad0 100644 --- a/wc-tier-and-package-prices.php +++ b/wc-tier-and-package-prices.php @@ -4,7 +4,7 @@ * Plugin Name: WooCommerce Tier and Package Prices * Plugin URI: https://src.bundespruefstelle.ch/wc-tier-package-prices * Description: Add tier pricing and package prices to WooCommerce products with configurable quantities at fixed prices - * Version: 1.1.0 + * Version: 1.1.1 * Author: Marco Graetsch * Author URI: https://src.bundespruefstelle.ch/magdev * Text Domain: wc-tier-package-prices @@ -22,7 +22,7 @@ if (!defined('ABSPATH')) { } // Define plugin constants -define('WC_TPP_VERSION', '1.1.0'); +define('WC_TPP_VERSION', '1.1.1'); define('WC_TPP_PLUGIN_DIR', plugin_dir_path(__FILE__)); define('WC_TPP_PLUGIN_URL', plugin_dir_url(__FILE__)); define('WC_TPP_PLUGIN_BASENAME', plugin_basename(__FILE__));