Merge branch 'dev'

This commit is contained in:
2025-12-30 00:48:46 +01:00
9 changed files with 103 additions and 8 deletions

View File

@@ -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/), 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). 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 ## [1.2.6] - 2025-12-30
### Fixed ### Fixed

View File

@@ -112,10 +112,16 @@
} }
/* Hide table headers when there are no pricing rules */ /* Hide table headers when there are no pricing rules */
/* Use :has() pseudo-class to check if tbody is empty */ /* Default: hide headers initially, JavaScript will show them when rows are added */
.wc-tpp-tiers-table:has(tbody.wc-tpp-tiers-container:empty) thead, .wc-tpp-tiers-table thead,
.wc-tpp-packages-table:has(tbody.wc-tpp-packages-container:empty) thead { .wc-tpp-packages-table thead {
display: none !important; 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 */ /* Checkbox styling improvements */

View File

@@ -10,6 +10,28 @@
let tierIndex = $('.wc-tpp-tier-pricing .wc-tpp-tier-row').length; let tierIndex = $('.wc-tpp-tier-pricing .wc-tpp-tier-row').length;
let packageIndex = $('.wc-tpp-package-pricing .wc-tpp-package-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 // Simple Product Handlers
// ======================================== // ========================================
@@ -21,6 +43,7 @@
const newRow = template.replace(/\{\{INDEX\}\}/g, tierIndex); const newRow = template.replace(/\{\{INDEX\}\}/g, tierIndex);
$('.wc-tpp-tier-pricing .wc-tpp-tiers-container').append(newRow); $('.wc-tpp-tier-pricing .wc-tpp-tiers-container').append(newRow);
tierIndex++; tierIndex++;
updateTableHeaders();
}); });
// Add package (simple products) // Add package (simple products)
@@ -30,6 +53,31 @@
const newRow = template.replace(/\{\{INDEX\}\}/g, packageIndex); const newRow = template.replace(/\{\{INDEX\}\}/g, packageIndex);
$('.wc-tpp-package-pricing .wc-tpp-packages-container').append(newRow); $('.wc-tpp-package-pricing .wc-tpp-packages-container').append(newRow);
packageIndex++; 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); const newRow = template.replace(/\{\{INDEX\}\}/g, currentIndex);
$tbody.append(newRow); $tbody.append(newRow);
updateTableHeaders();
}); });
// Add package (variations) // Add package (variations)
@@ -66,6 +115,7 @@
const newRow = template.replace(/\{\{INDEX\}\}/g, currentIndex); const newRow = template.replace(/\{\{INDEX\}\}/g, currentIndex);
$tbody.append(newRow); $tbody.append(newRow);
updateTableHeaders();
}); });
// ======================================== // ========================================
@@ -77,6 +127,7 @@
e.preventDefault(); e.preventDefault();
if (confirm('Are you sure you want to remove this tier?')) { if (confirm('Are you sure you want to remove this tier?')) {
$(this).closest('.wc-tpp-tier-row').remove(); $(this).closest('.wc-tpp-tier-row').remove();
updateTableHeaders();
} }
}); });
@@ -85,6 +136,7 @@
e.preventDefault(); e.preventDefault();
if (confirm('Are you sure you want to remove this package?')) { if (confirm('Are you sure you want to remove this package?')) {
$(this).closest('.wc-tpp-package-row').remove(); $(this).closest('.wc-tpp-package-row').remove();
updateTableHeaders();
} }
}); });

View File

@@ -1,7 +1,7 @@
{ {
"name": "magdev/wc-tier-package-prices", "name": "magdev/wc-tier-package-prices",
"description": "WooCommerce plugin for tier pricing and package prices with Twig templates", "description": "WooCommerce plugin for tier pricing and package prices with Twig templates",
"version": "1.2.6", "version": "1.2.7",
"type": "wordpress-plugin", "type": "wordpress-plugin",
"license": "GPL-2.0-or-later", "license": "GPL-2.0-or-later",
"authors": [ "authors": [

View File

@@ -17,7 +17,8 @@ if (!class_exists('WC_TPP_Product_Meta')) {
add_action('woocommerce_process_product_meta', array($this, 'save_tier_package_fields')); add_action('woocommerce_process_product_meta', array($this, 'save_tier_package_fields'));
// Variable product parent hooks (for default pricing) // 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 // Variable product variation hooks
add_action('woocommerce_variation_options_pricing', array($this, 'add_variation_pricing_fields'), 10, 3); add_action('woocommerce_variation_options_pricing', array($this, 'add_variation_pricing_fields'), 10, 3);

Binary file not shown.

View File

@@ -0,0 +1 @@
b52aec2e42c894a1949b5e5898105cf1 wc-tier-and-package-prices-1.2.7.zip

View File

@@ -0,0 +1 @@
7ae87ca85f7799ed716d3a81be8977908fadb33260dbc565f6b0d39188c8b025 wc-tier-and-package-prices-1.2.7.zip

View File

@@ -4,7 +4,7 @@
* Plugin Name: WooCommerce Tier and Package Prices * Plugin Name: WooCommerce Tier and Package Prices
* Plugin URI: https://src.bundespruefstelle.ch/magdev/wc-tier-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 * 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: Marco Graetsch
* Author URI: https://src.bundespruefstelle.ch/magdev * Author URI: https://src.bundespruefstelle.ch/magdev
* Text Domain: wc-tier-package-prices * Text Domain: wc-tier-package-prices
@@ -23,7 +23,7 @@ if (!defined('ABSPATH')) {
// Define plugin constants // Define plugin constants
if (!defined('WC_TPP_VERSION')) { 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')) { if (!defined('WC_TPP_PLUGIN_DIR')) {
define('WC_TPP_PLUGIN_DIR', plugin_dir_path(__FILE__)); define('WC_TPP_PLUGIN_DIR', plugin_dir_path(__FILE__));