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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user