You've already forked wc-licensed-product
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:
10
CHANGELOG.md
10
CHANGELOG.md
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [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
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -50,22 +50,20 @@ code.file-hash {
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* License Product Tab - Hidden by default, shown via JS based on product type */
|
||||
#woocommerce-product-data ul.wc-tabs li.show_if_licensed,
|
||||
#woocommerce-product-data ul.wc-tabs li.show_if_licensed-variable {
|
||||
/* License Settings Tab - Hidden by default, shown via JS based on product type */
|
||||
/* WooCommerce creates tab with class: {tab_key}_options (licensed_product_options) */
|
||||
#woocommerce-product-data ul.wc-tabs li.licensed_product_options {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* 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.show_if_licensed-variable.wclp-active {
|
||||
#woocommerce-product-data ul.wc-tabs li.licensed_product_options.wclp-active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Hide elements for non-licensed products */
|
||||
#woocommerce-product-data .hide_if_licensed {
|
||||
display: none !important;
|
||||
}
|
||||
/* Variations tab visibility for licensed-variable is handled by WooCommerce */
|
||||
/* We add show_if_licensed-variable class to the variations tab via PHP filter */
|
||||
|
||||
|
||||
/* Action Buttons */
|
||||
.wp-list-table .button-link-delete {
|
||||
|
||||
@@ -141,15 +141,23 @@ final class LicensedProductType
|
||||
|
||||
/**
|
||||
* Add product data tab for license settings
|
||||
* Also modify variations tab to show for licensed-variable products
|
||||
*/
|
||||
public function addProductDataTab(array $tabs): array
|
||||
{
|
||||
// Add our License Settings tab
|
||||
$tabs['licensed_product'] = [
|
||||
'label' => __('License Settings', 'wc-licensed-product'),
|
||||
'target' => 'licensed_product_data',
|
||||
'class' => ['show_if_licensed', 'show_if_licensed-variable'],
|
||||
'priority' => 21,
|
||||
];
|
||||
|
||||
// Make Variations tab also show for licensed-variable products
|
||||
if (isset($tabs['variations'])) {
|
||||
$tabs['variations']['class'][] = 'show_if_licensed-variable';
|
||||
}
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
@@ -643,77 +651,63 @@ final class LicensedProductType
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function($) {
|
||||
// Main function to handle all licensed product type visibility
|
||||
function toggleLicensedProductVisibility() {
|
||||
// Handle our custom License Settings tab, Product Versions meta box,
|
||||
// and show_if_licensed-variable elements
|
||||
function toggleOurElements() {
|
||||
var productType = $('#product-type').val();
|
||||
var isLicensed = productType === 'licensed';
|
||||
var isLicensedVariable = productType === 'licensed-variable';
|
||||
|
||||
// Handle License Settings tab visibility using class toggle (not show/hide)
|
||||
// This preserves proper CSS display values for tab list items
|
||||
// License Settings tab - use CSS class for visibility
|
||||
var $licenseTab = $('li.licensed_product_options');
|
||||
if (isLicensed || isLicensedVariable) {
|
||||
$('.show_if_licensed').addClass('wclp-active');
|
||||
$('.show_if_licensed-variable').addClass('wclp-active');
|
||||
$('.general_options').show();
|
||||
$('.pricing').show();
|
||||
$('.general_tab').show();
|
||||
$licenseTab.addClass('wclp-active');
|
||||
} else {
|
||||
$('.show_if_licensed').removeClass('wclp-active');
|
||||
$('.show_if_licensed-variable').removeClass('wclp-active');
|
||||
$licenseTab.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) {
|
||||
$('#wc_licensed_product_versions').show();
|
||||
$metaBox.css('display', '');
|
||||
} 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) {
|
||||
// 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();
|
||||
$('.hide_if_variable').hide();
|
||||
|
||||
// Show variations tab
|
||||
$('.variations_tab').show();
|
||||
$('.variations_options').show();
|
||||
|
||||
// Hide shipping tab (virtual products)
|
||||
$('.shipping_tab').hide();
|
||||
|
||||
// Ensure the variations panel can be displayed
|
||||
$('#variable_product_options').show();
|
||||
} else {
|
||||
// Let WooCommerce handle show_if_variable elements
|
||||
// We only need to hide our custom class when not licensed-variable
|
||||
// Don't hide show_if_licensed-variable when it's licensed (simple)
|
||||
if (!isLicensed) {
|
||||
$('.show_if_licensed-variable').not('.show_if_licensed').hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initial check on page load
|
||||
toggleLicensedProductVisibility();
|
||||
// Initial setup - run after WooCommerce has initialized
|
||||
setTimeout(toggleOurElements, 10);
|
||||
|
||||
// On product type change
|
||||
// On product type change - run after WooCommerce has processed
|
||||
$('#product-type').on('change', function() {
|
||||
// Use setTimeout to let WooCommerce finish its own processing first
|
||||
setTimeout(toggleLicensedProductVisibility, 100);
|
||||
setTimeout(toggleOurElements, 100);
|
||||
});
|
||||
|
||||
// Re-apply after WooCommerce AJAX operations that may reset visibility
|
||||
$(document).on('woocommerce_variations_loaded', toggleLicensedProductVisibility);
|
||||
$(document).on('woocommerce_variations_added', toggleLicensedProductVisibility);
|
||||
$(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);
|
||||
}
|
||||
// Re-apply after WooCommerce AJAX operations
|
||||
$(document).on('woocommerce_variations_loaded woocommerce_variations_added woocommerce_variations_saved', function() {
|
||||
setTimeout(toggleOurElements, 10);
|
||||
});
|
||||
|
||||
// Listen for WooCommerce product type show/hide trigger
|
||||
$('body').on('woocommerce-product-type-change', toggleLicensedProductVisibility);
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Plugin Name: WooCommerce 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.
|
||||
* Version: 0.5.14
|
||||
* Version: 0.5.15
|
||||
* Author: Marco Graetsch
|
||||
* Author URI: https://src.bundespruefstelle.ch/magdev
|
||||
* License: GPL-2.0-or-later
|
||||
@@ -28,7 +28,7 @@ if (!defined('ABSPATH')) {
|
||||
}
|
||||
|
||||
// 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_DIR', plugin_dir_path(__FILE__));
|
||||
define('WC_LICENSED_PRODUCT_PLUGIN_URL', plugin_dir_url(__FILE__));
|
||||
|
||||
Reference in New Issue
Block a user