You've already forked wc-tier-and-package-prices
Release version 1.2.0 - Add complete variable product support
This major feature release adds full support for WooCommerce variable products with variation-level pricing configuration. ## Key Features - Each product variation can have independent tier and package pricing - AJAX-based dynamic pricing table loading on variation selection - Admin UI integrated into WooCommerce variation panels - Full backward compatibility with existing simple product functionality - WooCommerce Blocks compatibility maintained ## Implementation Highlights - Effective ID pattern throughout codebase for variation handling - Variation-specific meta boxes with field prefix support - Template system updated to support both simple and variation products - JavaScript enhancements for variation selector integration - Cart logic updated to handle variation pricing correctly ## Files Changed - Core: wc-tier-and-package-prices.php (version 1.2.0), composer.json - Cart: includes/class-wc-tpp-cart.php (effective ID logic) - Frontend: includes/class-wc-tpp-frontend.php (AJAX endpoint, variation detection) - Admin: includes/class-wc-tpp-product-meta.php (variation hooks and methods) - Templates: templates/admin/*.twig (field prefix support, table structure) - JavaScript: assets/js/*.js (variation support) - Documentation: CHANGELOG.md, README.md, CLAUDE.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -244,6 +244,114 @@
|
||||
if ($quantityInput.length > 0 && $addToCartButton.length > 0) {
|
||||
updateAddToCartButton();
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Variable Product Support
|
||||
// ========================================
|
||||
|
||||
const $variationsForm = $('.variations_form');
|
||||
const $pricingTableContainer = $('.wc-tpp-pricing-table-container');
|
||||
|
||||
if ($variationsForm.length && $pricingTableContainer.length) {
|
||||
// Handle variation selection
|
||||
$variationsForm.on('found_variation', function(event, variation) {
|
||||
if (!variation.variation_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Show loading state
|
||||
$pricingTableContainer.html('<div class="wc-tpp-loading">Loading pricing...</div>').show();
|
||||
|
||||
// Fetch variation pricing via AJAX
|
||||
$.ajax({
|
||||
url: wcTppData.ajax_url,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wc_tpp_get_variation_pricing',
|
||||
nonce: wcTppData.nonce,
|
||||
variation_id: variation.variation_id
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success && response.data.has_pricing) {
|
||||
// Display the pricing table HTML
|
||||
$pricingTableContainer.html(response.data.html).show();
|
||||
|
||||
// Re-initialize event handlers for the new content
|
||||
initializePricingHandlers();
|
||||
|
||||
// Handle quantity restrictions
|
||||
if (response.data.restrict_to_packages) {
|
||||
$('input.qty').hide().closest('.quantity').hide();
|
||||
$('<style>.quantity { display: none !important; }</style>').appendTo('head');
|
||||
} else {
|
||||
$('input.qty').show().closest('.quantity').show();
|
||||
$('style:contains(".quantity { display: none")').remove();
|
||||
}
|
||||
} else {
|
||||
// No pricing for this variation
|
||||
$pricingTableContainer.html('').hide();
|
||||
$('input.qty').show().closest('.quantity').show();
|
||||
$('style:contains(".quantity { display: none")').remove();
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$pricingTableContainer.html('').hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Handle variation reset
|
||||
$variationsForm.on('reset_data', function() {
|
||||
$pricingTableContainer.html('').hide();
|
||||
$('input.qty').show().closest('.quantity').show();
|
||||
$('style:contains(".quantity { display: none")').remove();
|
||||
});
|
||||
|
||||
// Initialize pricing handlers for dynamically loaded content
|
||||
function initializePricingHandlers() {
|
||||
// Re-attach package selection handlers
|
||||
$('.wc-tpp-select-package').off('click').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
const $package = $(this).closest('.wc-tpp-package');
|
||||
const qty = parseInt($package.data('qty'));
|
||||
const $qtyInput = $('input.qty');
|
||||
|
||||
if ($qtyInput.length === 0 || $qtyInput.is(':hidden')) {
|
||||
// Create hidden input for restricted products
|
||||
if ($('.qty-hidden-input').length === 0) {
|
||||
$('.single_add_to_cart_button').before('<input type="hidden" name="quantity" class="qty qty-hidden-input" value="1" />');
|
||||
}
|
||||
$('.qty-hidden-input').val(qty);
|
||||
} else {
|
||||
$qtyInput.val(qty).trigger('change');
|
||||
}
|
||||
|
||||
// Highlight selected package
|
||||
$('.wc-tpp-package').removeClass('wc-tpp-selected');
|
||||
$package.addClass('wc-tpp-selected');
|
||||
|
||||
// Scroll to add to cart button
|
||||
$('html, body').animate({
|
||||
scrollTop: $('.single_add_to_cart_button').offset().top - 100
|
||||
}, 500);
|
||||
});
|
||||
|
||||
// Re-attach tier row click handlers
|
||||
$('.wc-tpp-tier-pricing-table tbody tr').off('click').on('click', function() {
|
||||
const minQty = parseInt($(this).data('min-qty'));
|
||||
const $qtyInput = $('input.qty');
|
||||
|
||||
if ($qtyInput.length > 0 && $qtyInput.is(':visible')) {
|
||||
$qtyInput.val(minQty).trigger('change');
|
||||
|
||||
// Scroll to quantity input
|
||||
$('html, body').animate({
|
||||
scrollTop: $qtyInput.offset().top - 100
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
|
||||
Reference in New Issue
Block a user