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:
@@ -6,18 +6,72 @@
|
||||
'use strict';
|
||||
|
||||
$(document).ready(function() {
|
||||
let tierIndex = $('.wc-tpp-tier-row').length;
|
||||
let packageIndex = $('.wc-tpp-package-row').length;
|
||||
// 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;
|
||||
|
||||
// Add tier
|
||||
$('.wc-tpp-add-tier').on('click', function(e) {
|
||||
// ========================================
|
||||
// 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-tiers-container').append(newRow);
|
||||
$('.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();
|
||||
@@ -26,15 +80,6 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Add package
|
||||
$('.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-packages-container').append(newRow);
|
||||
packageIndex++;
|
||||
});
|
||||
|
||||
// Remove package
|
||||
$(document).on('click', '.wc-tpp-remove-package', function(e) {
|
||||
e.preventDefault();
|
||||
@@ -43,7 +88,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Validate inputs
|
||||
// Validate quantity inputs
|
||||
$(document).on('input', 'input[name*="[min_qty]"], input[name*="[qty]"]', function() {
|
||||
const value = parseInt($(this).val());
|
||||
if (value < 1) {
|
||||
@@ -51,6 +96,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Validate price inputs
|
||||
$(document).on('input', 'input[name*="[price]"]', function() {
|
||||
const value = parseFloat($(this).val());
|
||||
if (value < 0) {
|
||||
|
||||
Reference in New Issue
Block a user