Fix tab rendering bug in WooCommerce product edit page (v0.5.15)

- Simplified JavaScript to avoid conflicts with WooCommerce's native show/hide logic
- Removed conflicting CSS rule for .hide_if_licensed
- License Settings tab uses CSS class toggle for proper display
- Variations tab properly shows for licensed-variable via woocommerce_product_data_tabs filter

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-27 17:39:55 +01:00
parent f9efe698ea
commit 72017f4c62
4 changed files with 61 additions and 59 deletions

View File

@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [0.5.15] - 2026-01-27
### Fixed
- Fixed tab rendering bug in WooCommerce product edit page when switching to licensed or licensed-variable product types
- Simplified JavaScript to avoid conflicts with WooCommerce's native show/hide logic
- Removed conflicting CSS rule for `.hide_if_licensed` that was causing layout issues
- License Settings tab now uses CSS class toggle (`.wclp-active`) instead of jQuery `.show()/.hide()` for proper display
- Variations tab now properly shows for licensed-variable products via `woocommerce_product_data_tabs` filter
## [0.5.14] - 2026-01-27 ## [0.5.14] - 2026-01-27
### Fixed ### Fixed

View File

@@ -50,22 +50,20 @@ code.file-hash {
color: #666; color: #666;
} }
/* License Product Tab - Hidden by default, shown via JS based on product type */ /* License Settings Tab - Hidden by default, shown via JS based on product type */
#woocommerce-product-data ul.wc-tabs li.show_if_licensed, /* WooCommerce creates tab with class: {tab_key}_options (licensed_product_options) */
#woocommerce-product-data ul.wc-tabs li.show_if_licensed-variable { #woocommerce-product-data ul.wc-tabs li.licensed_product_options {
display: none; display: none;
} }
/* When shown, restore proper display for tab list items */ /* When shown, restore proper display for tab list items */
#woocommerce-product-data ul.wc-tabs li.show_if_licensed.wclp-active, #woocommerce-product-data ul.wc-tabs li.licensed_product_options.wclp-active {
#woocommerce-product-data ul.wc-tabs li.show_if_licensed-variable.wclp-active {
display: block; display: block;
} }
/* Hide elements for non-licensed products */ /* Variations tab visibility for licensed-variable is handled by WooCommerce */
#woocommerce-product-data .hide_if_licensed { /* We add show_if_licensed-variable class to the variations tab via PHP filter */
display: none !important;
}
/* Action Buttons */ /* Action Buttons */
.wp-list-table .button-link-delete { .wp-list-table .button-link-delete {

View File

@@ -141,15 +141,23 @@ final class LicensedProductType
/** /**
* Add product data tab for license settings * Add product data tab for license settings
* Also modify variations tab to show for licensed-variable products
*/ */
public function addProductDataTab(array $tabs): array public function addProductDataTab(array $tabs): array
{ {
// Add our License Settings tab
$tabs['licensed_product'] = [ $tabs['licensed_product'] = [
'label' => __('License Settings', 'wc-licensed-product'), 'label' => __('License Settings', 'wc-licensed-product'),
'target' => 'licensed_product_data', 'target' => 'licensed_product_data',
'class' => ['show_if_licensed', 'show_if_licensed-variable'], 'class' => ['show_if_licensed', 'show_if_licensed-variable'],
'priority' => 21, 'priority' => 21,
]; ];
// Make Variations tab also show for licensed-variable products
if (isset($tabs['variations'])) {
$tabs['variations']['class'][] = 'show_if_licensed-variable';
}
return $tabs; return $tabs;
} }
@@ -643,77 +651,63 @@ final class LicensedProductType
?> ?>
<script type="text/javascript"> <script type="text/javascript">
jQuery(document).ready(function($) { jQuery(document).ready(function($) {
// Main function to handle all licensed product type visibility // Handle our custom License Settings tab, Product Versions meta box,
function toggleLicensedProductVisibility() { // and show_if_licensed-variable elements
function toggleOurElements() {
var productType = $('#product-type').val(); var productType = $('#product-type').val();
var isLicensed = productType === 'licensed'; var isLicensed = productType === 'licensed';
var isLicensedVariable = productType === 'licensed-variable'; var isLicensedVariable = productType === 'licensed-variable';
// Handle License Settings tab visibility using class toggle (not show/hide) // License Settings tab - use CSS class for visibility
// This preserves proper CSS display values for tab list items var $licenseTab = $('li.licensed_product_options');
if (isLicensed || isLicensedVariable) { if (isLicensed || isLicensedVariable) {
$('.show_if_licensed').addClass('wclp-active'); $licenseTab.addClass('wclp-active');
$('.show_if_licensed-variable').addClass('wclp-active');
$('.general_options').show();
$('.pricing').show();
$('.general_tab').show();
} else { } else {
$('.show_if_licensed').removeClass('wclp-active'); $licenseTab.removeClass('wclp-active');
$('.show_if_licensed-variable').removeClass('wclp-active'); // If License Settings panel is active, switch to General tab
if ($('#licensed_product_data').is(':visible')) {
$('li.general_options a').trigger('click');
}
} }
// Handle Product Versions meta box visibility // Product Versions meta box
var $metaBox = $('#wc_licensed_product_versions');
if (isLicensed || isLicensedVariable) { if (isLicensed || isLicensedVariable) {
$('#wc_licensed_product_versions').show(); $metaBox.css('display', '');
} else { } else {
$('#wc_licensed_product_versions').hide(); $metaBox.css('display', 'none');
} }
// Handle licensed-variable specific options // Handle show_if_licensed-variable elements (like Variations tab)
// WooCommerce doesn't know about our custom product types
if (isLicensedVariable) { if (isLicensedVariable) {
// Show variable product options $('.show_if_licensed-variable').show();
// Also show elements that should be visible for variable products
// since licensed-variable is a variable product type
$('.show_if_variable').show(); $('.show_if_variable').show();
$('.hide_if_variable').hide(); $('.hide_if_variable').hide();
} else {
// Show variations tab // Let WooCommerce handle show_if_variable elements
$('.variations_tab').show(); // We only need to hide our custom class when not licensed-variable
$('.variations_options').show(); // Don't hide show_if_licensed-variable when it's licensed (simple)
if (!isLicensed) {
// Hide shipping tab (virtual products) $('.show_if_licensed-variable').not('.show_if_licensed').hide();
$('.shipping_tab').hide(); }
// Ensure the variations panel can be displayed
$('#variable_product_options').show();
} }
} }
// Initial check on page load // Initial setup - run after WooCommerce has initialized
toggleLicensedProductVisibility(); setTimeout(toggleOurElements, 10);
// On product type change // On product type change - run after WooCommerce has processed
$('#product-type').on('change', function() { $('#product-type').on('change', function() {
// Use setTimeout to let WooCommerce finish its own processing first setTimeout(toggleOurElements, 100);
setTimeout(toggleLicensedProductVisibility, 100);
}); });
// Re-apply after WooCommerce AJAX operations that may reset visibility // Re-apply after WooCommerce AJAX operations
$(document).on('woocommerce_variations_loaded', toggleLicensedProductVisibility); $(document).on('woocommerce_variations_loaded woocommerce_variations_added woocommerce_variations_saved', function() {
$(document).on('woocommerce_variations_added', toggleLicensedProductVisibility); setTimeout(toggleOurElements, 10);
$(document).on('woocommerce_variations_saved', toggleLicensedProductVisibility);
// Handle AJAX complete events for attribute saving
$(document).ajaxComplete(function(event, xhr, settings) {
if (settings.data && (
settings.data.indexOf('action=woocommerce_save_attributes') !== -1 ||
settings.data.indexOf('action=woocommerce_load_variations') !== -1 ||
settings.data.indexOf('action=woocommerce_add_variation') !== -1
)) {
setTimeout(toggleLicensedProductVisibility, 100);
}
}); });
// Listen for WooCommerce product type show/hide trigger
$('body').on('woocommerce-product-type-change', toggleLicensedProductVisibility);
}); });
</script> </script>
<?php <?php

View File

@@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Licensed Product * Plugin Name: WooCommerce Licensed Product
* Plugin URI: https://src.bundespruefstelle.ch/magdev/wc-licensed-product * Plugin URI: https://src.bundespruefstelle.ch/magdev/wc-licensed-product
* Description: WooCommerce plugin to sell software products using license keys with domain-based validation. * Description: WooCommerce plugin to sell software products using license keys with domain-based validation.
* Version: 0.5.14 * Version: 0.5.15
* Author: Marco Graetsch * Author: Marco Graetsch
* Author URI: https://src.bundespruefstelle.ch/magdev * Author URI: https://src.bundespruefstelle.ch/magdev
* License: GPL-2.0-or-later * License: GPL-2.0-or-later
@@ -28,7 +28,7 @@ if (!defined('ABSPATH')) {
} }
// Plugin constants // Plugin constants
define('WC_LICENSED_PRODUCT_VERSION', '0.5.14'); define('WC_LICENSED_PRODUCT_VERSION', '0.5.15');
define('WC_LICENSED_PRODUCT_PLUGIN_FILE', __FILE__); define('WC_LICENSED_PRODUCT_PLUGIN_FILE', __FILE__);
define('WC_LICENSED_PRODUCT_PLUGIN_DIR', plugin_dir_path(__FILE__)); define('WC_LICENSED_PRODUCT_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('WC_LICENSED_PRODUCT_PLUGIN_URL', plugin_dir_url(__FILE__)); define('WC_LICENSED_PRODUCT_PLUGIN_URL', plugin_dir_url(__FILE__));