Add pricing system with tiers, seasons, and calculator (v0.2.0)
All checks were successful
Create Release Package / build-release (push) Successful in 1m19s
All checks were successful
Create Release Package / build-release (push) Successful in 1m19s
- Create PricingTier enum for short/mid/long-term pricing - Add Season class for seasonal pricing with date ranges - Implement Calculator for price calculations with breakdown - Add pricing meta box to Room post type - Create Seasons admin page for managing seasonal pricing - Add Pricing settings tab with tier thresholds - Support weekend surcharges and configurable weekend days - Add price column to room list admin Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -183,10 +183,107 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize pricing settings functionality.
|
||||
*/
|
||||
function initPricingSettings() {
|
||||
var $midTermInput = $('#wp_bnb_mid_term_max_nights');
|
||||
var $longTermMin = $('#wp-bnb-long-term-min');
|
||||
|
||||
if (!$midTermInput.length || !$longTermMin.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update long-term minimum display when mid-term max changes.
|
||||
$midTermInput.on('input', function() {
|
||||
$longTermMin.text($(this).val());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize season form validation.
|
||||
*/
|
||||
function initSeasonForm() {
|
||||
var $form = $('.bnb-season-form');
|
||||
|
||||
if (!$form.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate date format on input.
|
||||
$form.find('#season_start_date, #season_end_date').on('input', function() {
|
||||
var value = $(this).val();
|
||||
var isValid = /^\d{2}-\d{2}$/.test(value);
|
||||
|
||||
if (value.length > 0 && !isValid) {
|
||||
$(this).css('border-color', '#d63638');
|
||||
} else {
|
||||
$(this).css('border-color', '');
|
||||
}
|
||||
});
|
||||
|
||||
// Validate modifier range.
|
||||
$form.find('#season_modifier').on('input', function() {
|
||||
var value = parseFloat($(this).val());
|
||||
var $preview = $(this).siblings('.bnb-modifier-preview');
|
||||
|
||||
if ($preview.length === 0) {
|
||||
$preview = $('<span class="bnb-modifier-preview"></span>');
|
||||
$(this).after($preview);
|
||||
}
|
||||
|
||||
if (!isNaN(value) && value > 0) {
|
||||
var percentage = ((value - 1) * 100).toFixed(0);
|
||||
var text = '';
|
||||
if (percentage > 0) {
|
||||
text = '+' + percentage + '% ' + (wpBnbAdmin.i18n.increase || 'increase');
|
||||
$preview.css('color', '#d63638');
|
||||
} else if (percentage < 0) {
|
||||
text = percentage + '% ' + (wpBnbAdmin.i18n.discount || 'discount');
|
||||
$preview.css('color', '#00a32a');
|
||||
} else {
|
||||
text = wpBnbAdmin.i18n.normalPrice || 'Normal price';
|
||||
$preview.css('color', '#646970');
|
||||
}
|
||||
$preview.text(' = ' + text);
|
||||
} else {
|
||||
$preview.text('');
|
||||
}
|
||||
}).trigger('input');
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize pricing meta box interactions.
|
||||
*/
|
||||
function initPricingMetaBox() {
|
||||
var $pricingTable = $('.bnb-pricing-table');
|
||||
|
||||
if (!$pricingTable.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Highlight empty required prices.
|
||||
$pricingTable.find('input[type="number"]').on('blur', function() {
|
||||
var $input = $(this);
|
||||
var value = $input.val();
|
||||
var isShortTerm = $input.attr('id').indexOf('short_term') !== -1;
|
||||
|
||||
// Short-term price is recommended.
|
||||
if (isShortTerm && (value === '' || parseFloat(value) <= 0)) {
|
||||
$input.css('background-color', '#fcf0f1');
|
||||
} else {
|
||||
$input.css('background-color', '');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize on document ready.
|
||||
$(document).ready(function() {
|
||||
initLicenseManagement();
|
||||
initRoomGallery();
|
||||
initPricingSettings();
|
||||
initSeasonForm();
|
||||
initPricingMetaBox();
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
|
||||
Reference in New Issue
Block a user