diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d68463..5e30011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,39 @@ 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.2.6] - 2025-12-30 + +### Fixed + +- **Parent Product Pricing Forms Not Visible (Critical)**: Variable products were missing the pricing configuration forms on the parent product edit page. The v1.2.5 feature for parent product default pricing was implemented in the backend logic (cart calculations and frontend display) but the admin UI to configure these defaults was not added. Now variable product parents have a dedicated "Default Tier & Package Pricing for All Variations" section in the product edit page where administrators can configure default pricing that applies to all variations unless a specific variation overrides it. + +- **Table Headers Not Hiding When Empty**: The CSS selector for hiding table headers when no pricing rules exist was using an incorrect approach. The sibling selector `~` doesn't work when `` comes before `` in the HTML structure. Removed the sibling selector and kept only the `:has()` pseudo-class approach with `!important` flag for proper specificity. + +### Technical Details + +**Parent Product Forms Fix**: +- Added new method `add_variable_parent_pricing_fields()` in `WC_TPP_Product_Meta` class +- Hooked to `woocommerce_product_options_pricing` action but only displays for variable products +- Modified existing `add_tier_pricing_fields()` and `add_package_pricing_fields()` to skip variable products (they now only show for simple products) +- Parent product forms use same field names as simple products (`_wc_tpp_tiers`, `_wc_tpp_packages`, `_wc_tpp_restrict_to_packages`) +- Data is saved to parent product post meta using existing `save_tier_package_fields()` method +- Backend fallback logic from v1.2.5 now has matching admin UI for configuration + +**CSS Selector Fix**: +- Removed incorrect `.wc-tpp-tiers-container:empty ~ thead` selector (sibling selector can't target previous elements) +- Kept only `.wc-tpp-tiers-table:has(tbody.wc-tpp-tiers-container:empty) thead` with `!important` flag +- `:has()` pseudo-class is supported in modern browsers (Chrome 105+, Firefox 121+, Safari 15.4+) + +**User Impact**: +- Administrators can now configure default tier/package pricing on variable product parents (feature was non-functional in v1.2.5) +- Table headers properly hide when no pricing rules exist, creating cleaner admin interface +- No data migration needed - existing configurations remain intact + +### Changed Files + +- `includes/class-wc-tpp-product-meta.php` - Added `add_variable_parent_pricing_fields()` method; modified `add_tier_pricing_fields()` and `add_package_pricing_fields()` to skip variable products +- `assets/css/admin.css` - Fixed table header hiding CSS selector; removed incorrect sibling selector; added `!important` flag + ## [1.2.5] - 2025-12-30 ### Added diff --git a/CLAUDE.md b/CLAUDE.md index 80dbae5..eb15211 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -765,6 +765,12 @@ Roadmap for the upcoming development. 2. ~~Make it possible to define tier or package prices on variable products in the parent product as a default for that product and all variants of it unless a variant has its own tier or package prices.~~ ✅ **COMPLETED in v1.2.5** - Implemented parent product default pricing with automatic fallback. Variable products can define tier/package pricing once at parent level; variations inherit these defaults unless they have their own specific pricing. Added helper methods in cart class and updated all pricing/restriction checks to support parent fallback. +##### Fixes for v1.2.5 + +1. The table headers in admin are still visible. + +2. The parent product fallback on variable product is also not visible. + ##### Planned Enhancements for v1.2.6+ 1. Create different, selectable templates for tierprices and packages to use in the frontend. Make the new templates selectable globally on the settings-page, not per product. diff --git a/assets/css/admin.css b/assets/css/admin.css index 60b4dd0..346c6f5 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -112,15 +112,10 @@ } /* Hide table headers when there are no pricing rules */ -.wc-tpp-tiers-container:empty ~ thead, -.wc-tpp-packages-container:empty ~ thead { - display: none; -} - -/* Alternative approach: hide thead when tbody is empty (more reliable) */ +/* Use :has() pseudo-class to check if tbody is empty */ .wc-tpp-tiers-table:has(tbody.wc-tpp-tiers-container:empty) thead, .wc-tpp-packages-table:has(tbody.wc-tpp-packages-container:empty) thead { - display: none; + display: none !important; } /* Checkbox styling improvements */ diff --git a/composer.json b/composer.json index 56a2dea..3b9711a 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.2.5", + "version": "1.2.6", "type": "wordpress-plugin", "license": "GPL-2.0-or-later", "authors": [ diff --git a/includes/class-wc-tpp-product-meta.php b/includes/class-wc-tpp-product-meta.php index 4cfd7b7..23b72ca 100644 --- a/includes/class-wc-tpp-product-meta.php +++ b/includes/class-wc-tpp-product-meta.php @@ -16,13 +16,127 @@ if (!class_exists('WC_TPP_Product_Meta')) { add_action('woocommerce_product_options_pricing', array($this, 'add_package_pricing_fields')); add_action('woocommerce_process_product_meta', array($this, 'save_tier_package_fields')); + // Variable product parent hooks (for default pricing) + add_action('woocommerce_product_options_pricing', array($this, 'add_variable_parent_pricing_fields')); + // Variable product variation hooks add_action('woocommerce_variation_options_pricing', array($this, 'add_variation_pricing_fields'), 10, 3); add_action('woocommerce_save_product_variation', array($this, 'save_variation_pricing_fields'), 10, 2); } + /** + * Add tier and package pricing fields for variable product parents + * These serve as defaults for all variations unless overridden + */ + public function add_variable_parent_pricing_fields() { + global $post; + + // Only show for variable products, not simple products + $product = wc_get_product($post->ID); + if (!$product || !$product->is_type('variable')) { + return; + } + + ?> +
+

+ + +

+

+ +

+ + +
+

+ + + + + + + + + + + ID, '_wc_tpp_tiers', true); + if (!is_array($tiers)) { + $tiers = array(); + } + + foreach ($tiers as $index => $tier) { + $this->render_tier_row($index, $tier); + } + ?> + +
+

+ +

+
+ + +
+

+ + + + + + + + + + + ID, '_wc_tpp_packages', true); + if (!is_array($packages)) { + $packages = array(); + } + + foreach ($packages as $index => $package) { + $this->render_package_row($index, $package); + } + ?> + +
+

+ +

+ + '_wc_tpp_restrict_to_packages', + 'label' => __('Restrict to Package Quantities (Default)', 'wc-tier-package-prices'), + 'description' => __('Default restriction setting for all variations. Only allow quantities defined in packages above.', 'wc-tier-package-prices'), + 'desc_tip' => true, + )); + ?> +
+ + + + + +
+ ID); + if ($product && $product->is_type('variable')) { + return; + } + ?>

@@ -62,6 +176,13 @@ if (!class_exists('WC_TPP_Product_Meta')) { public function add_package_pricing_fields() { global $post; + + // Only show for simple products (variable products use add_variable_parent_pricing_fields) + $product = wc_get_product($post->ID); + if ($product && $product->is_type('variable')) { + return; + } + ?>

diff --git a/releases/wc-tier-and-package-prices-1.2.6.zip b/releases/wc-tier-and-package-prices-1.2.6.zip new file mode 100644 index 0000000..4b1b216 Binary files /dev/null and b/releases/wc-tier-and-package-prices-1.2.6.zip differ diff --git a/releases/wc-tier-and-package-prices-1.2.6.zip.md5 b/releases/wc-tier-and-package-prices-1.2.6.zip.md5 new file mode 100644 index 0000000..ef0da9b --- /dev/null +++ b/releases/wc-tier-and-package-prices-1.2.6.zip.md5 @@ -0,0 +1 @@ +b2c862fbad94f42f0756fb496a1dd920 wc-tier-and-package-prices-1.2.6.zip diff --git a/releases/wc-tier-and-package-prices-1.2.6.zip.sha256 b/releases/wc-tier-and-package-prices-1.2.6.zip.sha256 new file mode 100644 index 0000000..66fdb99 --- /dev/null +++ b/releases/wc-tier-and-package-prices-1.2.6.zip.sha256 @@ -0,0 +1 @@ +19a00c7fc2f42326f52d2da063766abd1c0b47d1701b9050c018bfb2bafae6f6 wc-tier-and-package-prices-1.2.6.zip diff --git a/wc-tier-and-package-prices.php b/wc-tier-and-package-prices.php index a21a6b2..ec2d5e9 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/magdev/wc-tier-package-prices * Description: Add tier pricing and package prices to WooCommerce products with configurable quantities at fixed prices - * Version: 1.2.5 + * Version: 1.2.6 * Author: Marco Graetsch * Author URI: https://src.bundespruefstelle.ch/magdev * Text Domain: wc-tier-package-prices @@ -23,7 +23,7 @@ if (!defined('ABSPATH')) { // Define plugin constants if (!defined('WC_TPP_VERSION')) { - define('WC_TPP_VERSION', '1.2.5'); + define('WC_TPP_VERSION', '1.2.6'); } if (!defined('WC_TPP_PLUGIN_DIR')) { define('WC_TPP_PLUGIN_DIR', plugin_dir_path(__FILE__));