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:
@@ -191,3 +191,135 @@
|
||||
vertical-align: middle;
|
||||
margin-right: 3px;
|
||||
}
|
||||
|
||||
/* Price column */
|
||||
.column-price {
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.bnb-no-price {
|
||||
color: #646970;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* Pricing Meta Box */
|
||||
.bnb-pricing-table h4 {
|
||||
margin: 0 0 10px 0;
|
||||
padding: 0;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #1d2327;
|
||||
}
|
||||
|
||||
.bnb-pricing-table tr:first-child th,
|
||||
.bnb-pricing-table tr:first-child td {
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
.bnb-price-input-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.bnb-price-input-wrapper input {
|
||||
width: 100px !important;
|
||||
}
|
||||
|
||||
.bnb-price-unit {
|
||||
color: #646970;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* Seasons Page */
|
||||
.bnb-seasons-description {
|
||||
background: #fff;
|
||||
border: 1px solid #c3c4c7;
|
||||
border-left: 4px solid #72aee6;
|
||||
padding: 12px 15px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.bnb-seasons-description p {
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
.bnb-no-seasons {
|
||||
background: #fff;
|
||||
border: 1px solid #c3c4c7;
|
||||
border-radius: 4px;
|
||||
padding: 40px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.bnb-no-seasons p {
|
||||
margin: 15px 0;
|
||||
}
|
||||
|
||||
.bnb-no-seasons .button {
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
/* Season List Columns */
|
||||
.column-name {
|
||||
width: 25%;
|
||||
}
|
||||
|
||||
.column-dates {
|
||||
width: 20%;
|
||||
}
|
||||
|
||||
.column-modifier {
|
||||
width: 20%;
|
||||
}
|
||||
|
||||
.column-priority {
|
||||
width: 10%;
|
||||
}
|
||||
|
||||
.column-status {
|
||||
width: 10%;
|
||||
}
|
||||
|
||||
.bnb-modifier-visual {
|
||||
font-size: 12px;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.bnb-status-active {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
color: #00a32a;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.bnb-status-active::before {
|
||||
content: "\f147";
|
||||
font-family: dashicons;
|
||||
margin-right: 3px;
|
||||
}
|
||||
|
||||
.bnb-status-inactive {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
color: #646970;
|
||||
}
|
||||
|
||||
.bnb-status-inactive::before {
|
||||
content: "\f460";
|
||||
font-family: dashicons;
|
||||
margin-right: 3px;
|
||||
}
|
||||
|
||||
/* Season Form */
|
||||
.bnb-season-form {
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
.bnb-season-form .form-table th {
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
.bnb-season-form input[type="text"].small-text {
|
||||
width: 80px;
|
||||
}
|
||||
|
||||
@@ -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