# WooCommerce Tier and Package Prices - Release 1.1.6

**Release Date:** December 22, 2025
**Version:** 1.1.6
**Package Size:** 54 KB
**Git Tag:** v1.1.6

## Download

**File:** `wc-tier-and-package-prices-1.1.6.zip`

### Checksums

**SHA256:**
```
730e366764449ac963bc85848ac8a91f654e4b35500ed3132a280ab4f215c80c
```

**MD5:**
```
dbea10acffdc849f9aa387d128cb6d6e
```

## What's New in 1.1.6

This is a **critical bug fix release** that resolves fatal errors introduced in versions 1.1.3, 1.1.4, and 1.1.5 during plugin activation.

### Critical Fixes
- **Plugin Activation Fatal Error** - FIXED
  - Fatal error caused by premature class instantiation before WooCommerce is loaded
  - Removed immediate class instantiation from `class-wc-tpp-cart.php` and `class-wc-tpp-frontend.php`
  - Ensures WooCommerce is fully loaded before registering hooks that depend on WC functions

### Technical Changes
- Moved `WC_TPP_Cart` and `WC_TPP_Frontend` instantiation to `woocommerce_loaded` hook
- Added `init_classes()` method to main plugin class for controlled class initialization
- Fixed hook registration timing to prevent accessing WooCommerce before it's available

## What Was Fixed

### The Problem (v1.1.3, v1.1.4, v1.1.5)

The previous three versions had a critical bug that caused fatal errors during plugin activation:

**Error Message:**
```
Fatal error: Call to undefined function WC()
Fatal error: Call to undefined function is_cart()
Fatal error: Call to undefined function is_checkout()
```

**Root Cause:**
- Classes `WC_TPP_Cart` and `WC_TPP_Frontend` were instantiated immediately in their files
- These classes register hooks that call WooCommerce functions (`WC()`, `is_cart()`, etc.)
- During plugin activation, these files are included before WooCommerce is loaded
- Hook registration attempts to call undefined WooCommerce functions
- Result: Fatal error and plugin activation failure

**Impact:**
- Plugin could not be activated on fresh installations
- Plugin could not be updated from v1.1.2 or earlier
- Affected all users attempting to install/update in v1.1.3-v1.1.5

### The Solution (v1.1.6)

**Before (v1.1.3-v1.1.5):**
```php
// At bottom of class-wc-tpp-cart.php and class-wc-tpp-frontend.php
new WC_TPP_Cart();    // Instantiated immediately!
new WC_TPP_Frontend(); // Instantiated immediately!
```

**After (v1.1.6):**
```php
// In main plugin file (wc-tier-and-package-prices.php)
private function includes() {
    // ... require files ...

    // Instantiate classes AFTER WooCommerce is loaded
    add_action('woocommerce_loaded', array($this, 'init_classes'));
}

public function init_classes() {
    new WC_TPP_Frontend();
    new WC_TPP_Cart();
}
```

**Why This Works:**
1. Class files are required but not instantiated during `includes()`
2. Main plugin hooks into `woocommerce_loaded` action
3. WooCommerce fully loads and defines all functions
4. `init_classes()` is called, safely instantiating classes
5. All WooCommerce functions are available when hooks are registered

## Affected Versions

### Broken Versions
- ❌ **v1.1.3** - Plugin activation fatal error
- ❌ **v1.1.4** - Plugin activation fatal error
- ❌ **v1.1.5** - Plugin activation fatal error (attempted fix failed)

### Fixed Versions
- ✅ **v1.1.6** - Plugin activation works correctly
- ✅ **v1.1.2** - No activation issues (last working version before bug)

## Installation

### New Installation

1. Download the ZIP file: `wc-tier-and-package-prices-1.1.6.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.1.5, 1.1.4, or 1.1.3

This is a **critical bug fix release**. If you have v1.1.3, v1.1.4, or v1.1.5 installed and working, upgrade to v1.1.6 immediately.

**Important Notes:**
- If your current version is **working**, you likely installed it on a site where WooCommerce was already active
- The bug only manifests during fresh activation or when upgrading with the plugin deactivated
- Upgrade is safe and preserves all settings and data

**Steps:**
1. Deactivate current version (if active)
2. Delete the plugin from WordPress admin
3. Upload and activate version 1.1.6
4. All existing settings and data will be automatically preserved
5. No additional configuration required

### Upgrade from 1.1.2 or Earlier

Safe to upgrade directly. This version includes all features from v1.1.0, v1.1.1, and v1.1.2, plus the critical activation fix.

**Steps:**
1. Deactivate the current version
2. Upload and activate version 1.1.6
3. All existing settings and data will be automatically preserved
4. Enjoy all new features with working activation

### Can't Activate v1.1.3, v1.1.4, or v1.1.5?

If you downloaded v1.1.3, v1.1.4, or v1.1.5 and cannot activate it, **use v1.1.6 instead**.

**Steps:**
1. Delete the broken version from WordPress admin (if present)
2. Download `wc-tier-and-package-prices-1.1.6.zip`
3. Upload and activate version 1.1.6
4. Configuration and setup will work correctly

### Requirements

- **WordPress:** 6.0 or higher
- **PHP:** 7.4 or higher
- **WooCommerce:** 8.0 or higher (must be installed and activated)

## What Features Are Included

Version 1.1.6 includes **all features** from v1.1.0 through v1.1.4, with the critical activation bug fixed:

### Complete Package Restriction Feature
- ✅ Catalog pages: "View Options" button (v1.1.2 + v1.1.4 enhanced styling)
- ✅ Product page: Quantity field hiding and package selection (v1.1.0)
- ✅ Add to cart: Server-side validation (v1.1.0)
- ✅ Classic cart: Quantity field hiding (v1.1.1 + v1.1.3 fixes)
- ✅ WooCommerce Blocks: Cart and mini-cart support (v1.1.4)
- ✅ All features now work with correct activation (v1.1.6)

### Settings
- ✅ Global setting to enable restrictions site-wide
- ✅ Per-product override for individual products
- ✅ Located in: WooCommerce > Settings > Tier & Package Prices

## Modified Files in 1.1.6

### Core Files Updated
- `wc-tier-and-package-prices.php`:
  - Added `init_classes()` method (lines 86-89)
  - Modified `includes()` to defer class instantiation (line 83)
  - No version number change (remains 1.1.6)

### PHP Classes Modified
- `includes/class-wc-tpp-cart.php`:
  - Removed immediate instantiation (removed `new WC_TPP_Cart();` from bottom)

- `includes/class-wc-tpp-frontend.php`:
  - Removed immediate instantiation (removed `new WC_TPP_Frontend();` from bottom)

### No Other Changes
- All functionality remains identical to v1.1.4
- No CSS changes
- No JavaScript changes
- No template changes
- No translation changes
- No feature changes

## Complete Feature Set

### 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
- ✅ Quantity restriction to packages only (v1.1.0)
- ✅ Cart quantity enforcement (v1.1.1 + v1.1.3)
- ✅ Catalog button modification (v1.1.2 + v1.1.4 enhanced)
- ✅ WooCommerce Blocks support (v1.1.4)
- ✅ Working plugin activation (v1.1.6 - FIXED)

### Admin Features
- ✅ WooCommerce Settings integration
- ✅ Easy-to-use product meta boxes
- ✅ Configurable display positions
- ✅ Native WooCommerce UI
- ✅ Global restriction setting
- ✅ Per-product restriction override

### Frontend Features
- ✅ Beautiful pricing tables (Twig templates)
- ✅ Real-time cart updates
- ✅ Responsive design
- ✅ 3 languages supported
- ✅ Package-only selection mode
- ✅ Automatic quantity field hiding (product page & cart)
- ✅ Visual package selection
- ✅ Read-only cart quantity display
- ✅ Professional "View Options" button (v1.1.4 enhanced)
- ✅ WooCommerce Blocks compatibility (v1.1.4)

### Validation & Security
- ✅ Client-side JavaScript validation
- ✅ Server-side cart validation
- ✅ Cart quantity bypass prevention
- ✅ Catalog add-to-cart prevention
- ✅ Store API integration (v1.1.4)
- ✅ User-friendly error messages
- ✅ WooCommerce HPOS compatible
- ✅ Theme/plugin conflict resistant
- ✅ WooCommerce Blocks compatible (v1.1.4)
- ✅ Proper plugin activation (v1.1.6 - FIXED)

## Breaking Changes

**None.** This release is fully backward compatible with v1.1.2 and all v1.0.x versions.

### About v1.1.3, v1.1.4, v1.1.5

These versions had activation bugs and should not be used. If you have them installed and working, upgrade to v1.1.6 for stability.

## Migration Notes

### From 1.1.5, 1.1.4, or 1.1.3
- Immediate upgrade recommended (critical bug fix)
- No functionality changes, only activation fix
- All settings preserved
- No configuration needed

### From 1.1.2 or Earlier
- All v1.1.0+ features included automatically
- Restriction features remain as configured
- WooCommerce Blocks now fully supported
- Plugin activation now works correctly

### 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)
4. Cart quantity is read-only text (not a dropdown of package options)
5. "View Options" button inherits theme colors (not customizable separately)

### Future Enhancements
These features may be added in future versions:
- Customizable "View Options" button text and colors
- Cart package quantity dropdown selector
- Variation-level restriction control
- Restrict to tier quantities option
- Minimum/maximum package selection limits

## Changelog Summary

### Version History
- **v1.1.6** (2025-12-22) - Critical fix for plugin activation
- **v1.1.5** (2025-12-21) - Critical bug fix attempt (incomplete)
- **v1.1.4** (2025-12-21) - WooCommerce Blocks support + improved button styling
- **v1.1.3** (2025-12-21) - Cart quantity visibility bug fix
- **v1.1.2** (2025-12-21) - Catalog button modification
- **v1.1.1** (2025-12-21) - Cart quantity bypass fix
- **v1.1.0** (2025-12-21) - Package quantity restriction feature
- **v1.0.2** (2025-12-21) - WooCommerce Settings integration
- **v1.0.1** (2025-12-21) - Twig template engine integration
- **v1.0.0** (2025-12-21) - Initial release

## User Impact

### Before v1.1.6
- Unable to activate plugin on fresh installations
- Unable to update from v1.1.2 or earlier with plugin deactivated
- Fatal errors during activation process
- Plugin unusable for new users

### After v1.1.6
- Plugin activates correctly on all WordPress installations
- Safe updates from any previous version
- All features work as intended
- Production ready for all users

## Recommendation

### For New Users
- ✅ **Use v1.1.6** - Latest stable version with all features and working activation

### For Users on v1.1.5, v1.1.4, or v1.1.3
- ⚠️ **Upgrade to v1.1.6** - Critical bug fix for stability

### For Users on v1.1.2 or Earlier
- ✅ **Upgrade to v1.1.6** - Get all new features plus stable activation

## Support

- **Documentation:** See README.md and CHANGELOG.md
- **Previous Release:** See RELEASE-INFO-1.1.4.md
- **Issues:** https://src.bundespruefstelle.ch/magdev/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.

**Critical Update:** Version 1.1.6 is a **critical update** for anyone on v1.1.3, v1.1.4, or v1.1.5. The plugin activation bug is now fixed and all features work correctly.
