Fix critical error and variants tab on licensed variable products (v0.5.8)

- Fixed critical error on frontend product pages for licensed variable products
- Variable product add-to-cart template now passes required variables
- Variants tab no longer disappears when saving attributes
- Added WooCommerce AJAX event listeners for tab visibility

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-27 13:34:27 +01:00
parent 90cb8d97bd
commit 169eed65eb
3 changed files with 63 additions and 5 deletions

View File

@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [0.5.8] - 2026-01-27
### Fixed
- **CRITICAL:** Fixed critical error on frontend product pages for licensed variable products
- Variable product add-to-cart template now passes required variables (`available_variations`, `attributes`, `selected_attributes`)
- Variants tab no longer disappears when saving attributes on licensed variable products
- Added WooCommerce AJAX event listeners to maintain tab visibility during attribute operations
### Changed
- Improved JavaScript event handling for licensed-variable product type in admin
- Added listeners for `woocommerce_variations_loaded`, `woocommerce_variations_added`, `woocommerce_variations_saved` events
- Added AJAX complete handler for attribute save operations
## [0.5.7] - 2026-01-27
### Changed

View File

@@ -201,19 +201,21 @@ final class LicensedProductType
</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
// Show/hide panels based on product type
// Show/hide panels based on product type for license settings tab
function toggleLicensedProductOptions() {
var productType = $('#product-type').val();
var isLicensed = productType === 'licensed';
var isLicensedVariable = productType === 'licensed-variable';
if (isLicensed || isLicensedVariable) {
// Show license settings tab
$('.show_if_licensed').show();
$('.show_if_licensed-variable').show();
$('.general_options').show();
$('.pricing').show();
$('.general_tab').show();
} else {
// Hide license settings tab for other product types
$('.show_if_licensed').hide();
$('.show_if_licensed-variable').hide();
}
@@ -334,7 +336,23 @@ final class LicensedProductType
*/
public function variableAddToCartTemplate(): void
{
wc_get_template('single-product/add-to-cart/variable.php');
global $product;
if (!$product instanceof \WC_Product_Variable) {
return;
}
// Get variations count to determine if we should load them via AJAX
$getVariations = count($product->get_children()) <= apply_filters('woocommerce_ajax_variation_threshold', 30, $product);
wc_get_template(
'single-product/add-to-cart/variable.php',
[
'available_variations' => $getVariations ? $product->get_available_variations() : false,
'attributes' => $product->get_variation_attributes(),
'selected_attributes' => $product->get_default_attributes(),
]
);
}
/**
@@ -507,9 +525,13 @@ final class LicensedProductType
// Show general and variations tabs
$('.general_tab').show();
$('.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();
}
}
@@ -518,8 +540,29 @@ final class LicensedProductType
// On product type change
$('#product-type').on('change', function() {
toggleLicensedVariableOptions();
// Use setTimeout to let WooCommerce finish its own processing first
setTimeout(toggleLicensedVariableOptions, 100);
});
// Re-apply after WooCommerce AJAX operations that may reset visibility
$(document).on('woocommerce_variations_loaded', toggleLicensedVariableOptions);
$(document).on('woocommerce_variations_added', toggleLicensedVariableOptions);
$(document).on('woocommerce_variations_saved', toggleLicensedVariableOptions);
// Handle AJAX complete events for attribute saving
$(document).ajaxComplete(function(event, xhr, settings) {
// Check if this was a product data save or attribute action
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(toggleLicensedVariableOptions, 100);
}
});
// Also listen for the WooCommerce product type show/hide trigger
$('body').on('woocommerce-product-type-change', toggleLicensedVariableOptions);
});
</script>
<?php

View File

@@ -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.7
* Version: 0.5.8
* 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.7');
define('WC_LICENSED_PRODUCT_VERSION', '0.5.8');
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__));