You've already forked wc-licensed-product
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:
15
CHANGELOG.md
15
CHANGELOG.md
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [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
|
## [0.5.7] - 2026-01-27
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
@@ -201,19 +201,21 @@ final class LicensedProductType
|
|||||||
</div>
|
</div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
jQuery(document).ready(function($) {
|
jQuery(document).ready(function($) {
|
||||||
// Show/hide panels based on product type
|
// Show/hide panels based on product type for license settings tab
|
||||||
function toggleLicensedProductOptions() {
|
function toggleLicensedProductOptions() {
|
||||||
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';
|
||||||
|
|
||||||
if (isLicensed || isLicensedVariable) {
|
if (isLicensed || isLicensedVariable) {
|
||||||
|
// Show license settings tab
|
||||||
$('.show_if_licensed').show();
|
$('.show_if_licensed').show();
|
||||||
$('.show_if_licensed-variable').show();
|
$('.show_if_licensed-variable').show();
|
||||||
$('.general_options').show();
|
$('.general_options').show();
|
||||||
$('.pricing').show();
|
$('.pricing').show();
|
||||||
$('.general_tab').show();
|
$('.general_tab').show();
|
||||||
} else {
|
} else {
|
||||||
|
// Hide license settings tab for other product types
|
||||||
$('.show_if_licensed').hide();
|
$('.show_if_licensed').hide();
|
||||||
$('.show_if_licensed-variable').hide();
|
$('.show_if_licensed-variable').hide();
|
||||||
}
|
}
|
||||||
@@ -334,7 +336,23 @@ final class LicensedProductType
|
|||||||
*/
|
*/
|
||||||
public function variableAddToCartTemplate(): void
|
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
|
// Show general and variations tabs
|
||||||
$('.general_tab').show();
|
$('.general_tab').show();
|
||||||
$('.variations_tab').show();
|
$('.variations_tab').show();
|
||||||
|
$('.variations_options').show();
|
||||||
|
|
||||||
// Hide shipping tab (virtual products)
|
// Hide shipping tab (virtual products)
|
||||||
$('.shipping_tab').hide();
|
$('.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
|
// On product type change
|
||||||
$('#product-type').on('change', function() {
|
$('#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>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
|
|||||||
@@ -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.7
|
* Version: 0.5.8
|
||||||
* 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.7');
|
define('WC_LICENSED_PRODUCT_VERSION', '0.5.8');
|
||||||
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__));
|
||||||
|
|||||||
Reference in New Issue
Block a user