You've already forked wc-tier-and-package-prices
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>
109 lines
4.1 KiB
JavaScript
109 lines
4.1 KiB
JavaScript
/**
|
|
* Admin JavaScript for WooCommerce Tier and Package Prices
|
|
*/
|
|
|
|
(function($) {
|
|
'use strict';
|
|
|
|
$(document).ready(function() {
|
|
// Initialize indexes for simple products
|
|
let tierIndex = $('.wc-tpp-tier-pricing .wc-tpp-tier-row').length;
|
|
let packageIndex = $('.wc-tpp-package-pricing .wc-tpp-package-row').length;
|
|
|
|
// ========================================
|
|
// Simple Product Handlers
|
|
// ========================================
|
|
|
|
// Add tier (simple products)
|
|
$('.wc-tpp-tier-pricing .wc-tpp-add-tier').on('click', function(e) {
|
|
e.preventDefault();
|
|
const template = $('#wc-tpp-tier-row-template').html();
|
|
const newRow = template.replace(/\{\{INDEX\}\}/g, tierIndex);
|
|
$('.wc-tpp-tier-pricing .wc-tpp-tiers-container').append(newRow);
|
|
tierIndex++;
|
|
});
|
|
|
|
// Add package (simple products)
|
|
$('.wc-tpp-package-pricing .wc-tpp-add-package').on('click', function(e) {
|
|
e.preventDefault();
|
|
const template = $('#wc-tpp-package-row-template').html();
|
|
const newRow = template.replace(/\{\{INDEX\}\}/g, packageIndex);
|
|
$('.wc-tpp-package-pricing .wc-tpp-packages-container').append(newRow);
|
|
packageIndex++;
|
|
});
|
|
|
|
// ========================================
|
|
// Variable Product Variation Handlers
|
|
// ========================================
|
|
|
|
// Add tier (variations)
|
|
$(document).on('click', '.wc-tpp-variation-pricing .wc-tpp-add-tier', function(e) {
|
|
e.preventDefault();
|
|
const $button = $(this);
|
|
const loop = $button.data('loop');
|
|
const $container = $button.closest('.wc-tpp-variation-pricing');
|
|
const $tbody = $container.find('.wc-tpp-variation-tiers .wc-tpp-tiers-container');
|
|
const template = $('#wc-tpp-variation-tier-row-template-' + loop).html();
|
|
|
|
// Count existing rows to get next index
|
|
const currentIndex = $tbody.find('tr').length;
|
|
const newRow = template.replace(/\{\{INDEX\}\}/g, currentIndex);
|
|
|
|
$tbody.append(newRow);
|
|
});
|
|
|
|
// Add package (variations)
|
|
$(document).on('click', '.wc-tpp-variation-pricing .wc-tpp-add-package', function(e) {
|
|
e.preventDefault();
|
|
const $button = $(this);
|
|
const loop = $button.data('loop');
|
|
const $container = $button.closest('.wc-tpp-variation-pricing');
|
|
const $tbody = $container.find('.wc-tpp-variation-packages .wc-tpp-packages-container');
|
|
const template = $('#wc-tpp-variation-package-row-template-' + loop).html();
|
|
|
|
// Count existing rows to get next index
|
|
const currentIndex = $tbody.find('tr').length;
|
|
const newRow = template.replace(/\{\{INDEX\}\}/g, currentIndex);
|
|
|
|
$tbody.append(newRow);
|
|
});
|
|
|
|
// ========================================
|
|
// Common Handlers (both simple and variations)
|
|
// ========================================
|
|
|
|
// Remove tier
|
|
$(document).on('click', '.wc-tpp-remove-tier', function(e) {
|
|
e.preventDefault();
|
|
if (confirm('Are you sure you want to remove this tier?')) {
|
|
$(this).closest('.wc-tpp-tier-row').remove();
|
|
}
|
|
});
|
|
|
|
// Remove package
|
|
$(document).on('click', '.wc-tpp-remove-package', function(e) {
|
|
e.preventDefault();
|
|
if (confirm('Are you sure you want to remove this package?')) {
|
|
$(this).closest('.wc-tpp-package-row').remove();
|
|
}
|
|
});
|
|
|
|
// Validate quantity inputs
|
|
$(document).on('input', 'input[name*="[min_qty]"], input[name*="[qty]"]', function() {
|
|
const value = parseInt($(this).val());
|
|
if (value < 1) {
|
|
$(this).val(1);
|
|
}
|
|
});
|
|
|
|
// Validate price inputs
|
|
$(document).on('input', 'input[name*="[price]"]', function() {
|
|
const value = parseFloat($(this).val());
|
|
if (value < 0) {
|
|
$(this).val(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
})(jQuery);
|