diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e30011..2c25e55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,40 @@ 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.7] - 2025-12-30 + +### Fixed + +- **Variable Product Forms Still Not Showing (Critical)**: The v1.2.6 fix used the wrong WooCommerce hook. The `woocommerce_product_options_pricing` hook only fires for simple products, not variable products. Changed to use `woocommerce_product_options_general_product_data` hook which fires for all product types after the general tab, allowing the code to check product type and conditionally display the parent pricing fields. + +- **Table Headers Still Visible When Empty (Critical)**: The CSS `:has()` pseudo-class approach from v1.2.6 wasn't working reliably across all browsers. Implemented a JavaScript-based solution that adds/removes a `has-rows` class on tables based on whether they contain pricing rules. Headers now hide by default and show only when the table has rows, with JavaScript updating the state when rows are added or removed. + +### Technical Details + +**Variable Product Hook Fix**: +- Changed from `woocommerce_product_options_pricing` to `woocommerce_product_options_general_product_data` +- The general product data hook fires for all product types +- Method still checks `$product->is_type('variable')` to only show for variable products +- This ensures forms appear in the correct location in the WordPress admin + +**Table Header Visibility Fix**: +- Replaced CSS-only `:has()` solution with JavaScript + CSS class approach +- CSS now uses `.wc-tpp-tiers-table.has-rows thead` to show headers +- Added `updateTableHeaders()` JavaScript function that checks row count and toggles class +- Function is called on page load and after any add/remove row operation +- Works reliably across all browsers without requiring modern CSS features + +**User Impact**: +- Variable product parent pricing forms now actually appear in the WordPress admin +- Table headers properly hide when empty and show when populated +- No browser compatibility issues - works in all modern browsers + +### Changed Files + +- `includes/class-wc-tpp-product-meta.php` - Changed hook from `woocommerce_product_options_pricing` to `woocommerce_product_options_general_product_data` +- `assets/css/admin.css` - Replaced `:has()` pseudo-class with class-based approach +- `assets/js/admin.js` - Added `updateTableHeaders()` function and calls after all row operations; added handlers for variable product parent forms + ## [1.2.6] - 2025-12-30 ### Fixed diff --git a/assets/css/admin.css b/assets/css/admin.css index 346c6f5..d211170 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -112,10 +112,16 @@ } /* Hide table headers when there are no pricing rules */ -/* 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 !important; +/* Default: hide headers initially, JavaScript will show them when rows are added */ +.wc-tpp-tiers-table thead, +.wc-tpp-packages-table thead { + display: none; +} + +/* Show headers when table has pricing rows */ +.wc-tpp-tiers-table.has-rows thead, +.wc-tpp-packages-table.has-rows thead { + display: table-header-group !important; } /* Checkbox styling improvements */ diff --git a/assets/js/admin.js b/assets/js/admin.js index a4c3c82..577b78e 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -10,6 +10,28 @@ let tierIndex = $('.wc-tpp-tier-pricing .wc-tpp-tier-row').length; let packageIndex = $('.wc-tpp-package-pricing .wc-tpp-package-row').length; + // Function to update table header visibility + function updateTableHeaders() { + // Check all tier tables + $('.wc-tpp-tiers-table').each(function() { + const $table = $(this); + const $tbody = $table.find('.wc-tpp-tiers-container'); + const hasRows = $tbody.find('tr').length > 0; + $table.toggleClass('has-rows', hasRows); + }); + + // Check all package tables + $('.wc-tpp-packages-table').each(function() { + const $table = $(this); + const $tbody = $table.find('.wc-tpp-packages-container'); + const hasRows = $tbody.find('tr').length > 0; + $table.toggleClass('has-rows', hasRows); + }); + } + + // Initialize table headers on page load + updateTableHeaders(); + // ======================================== // Simple Product Handlers // ======================================== @@ -21,6 +43,7 @@ const newRow = template.replace(/\{\{INDEX\}\}/g, tierIndex); $('.wc-tpp-tier-pricing .wc-tpp-tiers-container').append(newRow); tierIndex++; + updateTableHeaders(); }); // Add package (simple products) @@ -30,6 +53,31 @@ const newRow = template.replace(/\{\{INDEX\}\}/g, packageIndex); $('.wc-tpp-package-pricing .wc-tpp-packages-container').append(newRow); packageIndex++; + updateTableHeaders(); + }); + + // ======================================== + // Variable Product Parent Handlers + // ======================================== + + // Add tier (variable product parent default pricing) + $('.wc-tpp-variable-parent-pricing .wc-tpp-add-tier').on('click', function(e) { + e.preventDefault(); + const template = $('#wc-tpp-tier-row-template').html(); + const newRow = template.replace(/\{\{INDEX\}\}/g, tierIndex); + $('.wc-tpp-variable-parent-pricing .wc-tpp-tiers-container').append(newRow); + tierIndex++; + updateTableHeaders(); + }); + + // Add package (variable product parent default pricing) + $('.wc-tpp-variable-parent-pricing .wc-tpp-add-package').on('click', function(e) { + e.preventDefault(); + const template = $('#wc-tpp-package-row-template').html(); + const newRow = template.replace(/\{\{INDEX\}\}/g, packageIndex); + $('.wc-tpp-variable-parent-pricing .wc-tpp-packages-container').append(newRow); + packageIndex++; + updateTableHeaders(); }); // ======================================== @@ -50,6 +98,7 @@ const newRow = template.replace(/\{\{INDEX\}\}/g, currentIndex); $tbody.append(newRow); + updateTableHeaders(); }); // Add package (variations) @@ -66,6 +115,7 @@ const newRow = template.replace(/\{\{INDEX\}\}/g, currentIndex); $tbody.append(newRow); + updateTableHeaders(); }); // ======================================== @@ -77,6 +127,7 @@ e.preventDefault(); if (confirm('Are you sure you want to remove this tier?')) { $(this).closest('.wc-tpp-tier-row').remove(); + updateTableHeaders(); } }); @@ -85,6 +136,7 @@ e.preventDefault(); if (confirm('Are you sure you want to remove this package?')) { $(this).closest('.wc-tpp-package-row').remove(); + updateTableHeaders(); } }); diff --git a/composer.json b/composer.json index 3b9711a..54406c7 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.6", + "version": "1.2.7", "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 23b72ca..2a5c776 100644 --- a/includes/class-wc-tpp-product-meta.php +++ b/includes/class-wc-tpp-product-meta.php @@ -17,7 +17,8 @@ if (!class_exists('WC_TPP_Product_Meta')) { 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')); + // Use product_options_general_product_data which shows for all product types after the general tab + add_action('woocommerce_product_options_general_product_data', 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); diff --git a/releases/wc-tier-and-package-prices-1.2.7.zip b/releases/wc-tier-and-package-prices-1.2.7.zip new file mode 100644 index 0000000..dc716fc Binary files /dev/null and b/releases/wc-tier-and-package-prices-1.2.7.zip differ diff --git a/releases/wc-tier-and-package-prices-1.2.7.zip.md5 b/releases/wc-tier-and-package-prices-1.2.7.zip.md5 new file mode 100644 index 0000000..718b71b --- /dev/null +++ b/releases/wc-tier-and-package-prices-1.2.7.zip.md5 @@ -0,0 +1 @@ +b52aec2e42c894a1949b5e5898105cf1 wc-tier-and-package-prices-1.2.7.zip diff --git a/releases/wc-tier-and-package-prices-1.2.7.zip.sha256 b/releases/wc-tier-and-package-prices-1.2.7.zip.sha256 new file mode 100644 index 0000000..5003212 --- /dev/null +++ b/releases/wc-tier-and-package-prices-1.2.7.zip.sha256 @@ -0,0 +1 @@ +7ae87ca85f7799ed716d3a81be8977908fadb33260dbc565f6b0d39188c8b025 wc-tier-and-package-prices-1.2.7.zip diff --git a/wc-tier-and-package-prices.php b/wc-tier-and-package-prices.php index ec2d5e9..1ef25be 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.6 + * Version: 1.2.7 * 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.6'); + define('WC_TPP_VERSION', '1.2.7'); } if (!defined('WC_TPP_PLUGIN_DIR')) { define('WC_TPP_PLUGIN_DIR', plugin_dir_path(__FILE__));