|
@@ -105,16 +105,21 @@
|
|
|
|
|
|
|
|
function buildVariantSelect(initialVariationId) {
|
|
function buildVariantSelect(initialVariationId) {
|
|
|
var $select = $('<select class="studiou-fpp-card-variant"></select>');
|
|
var $select = $('<select class="studiou-fpp-card-variant"></select>');
|
|
|
- $select.append('<option value="0">' + escHtml(i18n.selectVariant || 'Select variant') + '</option>');
|
|
|
|
|
|
|
+ $select.append($('<option></option>').val(0).text(i18n.selectVariant || 'Select variant'));
|
|
|
for (var i = 0; i < variants.length; i++) {
|
|
for (var i = 0; i < variants.length; i++) {
|
|
|
var v = variants[i];
|
|
var v = variants[i];
|
|
|
- var priceLabel = v.base_price ? ' — ' + formatPrice(v.base_price) : '';
|
|
|
|
|
|
|
+ // <option> text nodes cannot render HTML, so use a plain-text price formatter
|
|
|
|
|
+ var priceLabel = v.base_price ? ' — ' + formatPricePlain(v.base_price) : '';
|
|
|
|
|
+ var label = v.label + priceLabel;
|
|
|
|
|
+ if (!v.in_stock) {
|
|
|
|
|
+ label += ' — ' + (i18n.outOfStock || 'out of stock');
|
|
|
|
|
+ }
|
|
|
var $opt = $('<option></option>')
|
|
var $opt = $('<option></option>')
|
|
|
.val(v.id)
|
|
.val(v.id)
|
|
|
- .text(v.label + priceLabel)
|
|
|
|
|
|
|
+ .text(label)
|
|
|
.attr('data-base-price', v.base_price);
|
|
.attr('data-base-price', v.base_price);
|
|
|
if (!v.in_stock) {
|
|
if (!v.in_stock) {
|
|
|
- $opt.prop('disabled', true).text(v.label + priceLabel + ' — ' + (i18n.outOfStock || 'out of stock'));
|
|
|
|
|
|
|
+ $opt.prop('disabled', true);
|
|
|
}
|
|
}
|
|
|
$select.append($opt);
|
|
$select.append($opt);
|
|
|
}
|
|
}
|
|
@@ -623,6 +628,23 @@
|
|
|
return formatPriceHtml(amount);
|
|
return formatPriceHtml(amount);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Plain-text price (no HTML) — used for <option> labels where spans aren't rendered
|
|
|
|
|
+ function formatPricePlain(amount) {
|
|
|
|
|
+ var c = studiouWcfppFront.currency || {};
|
|
|
|
|
+ var decimals = parseInt(c.decimals, 10); if (isNaN(decimals)) decimals = 2;
|
|
|
|
|
+ var decSep = c.decimalSeparator || '.';
|
|
|
|
|
+ var thouSep = c.thousandSeparator || ',';
|
|
|
|
|
+ var fmt = c.priceFormat || '%1$s%2$s';
|
|
|
|
|
+ var symbol = c.symbol || '';
|
|
|
|
|
+ var fixed = parseFloat(amount).toFixed(decimals);
|
|
|
|
|
+ var parts = fixed.split('.');
|
|
|
|
|
+ var intPart = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, thouSep);
|
|
|
|
|
+ var decPart = parts.length > 1 ? parts[1] : '';
|
|
|
|
|
+ var numStr = decPart ? intPart + decSep + decPart : intPart;
|
|
|
|
|
+ // strip any HTML tags that might arrive from priceFormat (defensive)
|
|
|
|
|
+ return fmt.replace('%1$s', symbol).replace('%2$s', numStr).replace(/<[^>]*>/g, '');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function formatPriceHtml(amount) {
|
|
function formatPriceHtml(amount) {
|
|
|
var c = studiouWcfppFront.currency || {};
|
|
var c = studiouWcfppFront.currency || {};
|
|
|
var decimals = parseInt(c.decimals, 10); if (isNaN(decimals)) decimals = 2;
|
|
var decimals = parseInt(c.decimals, 10); if (isNaN(decimals)) decimals = 2;
|