Where is the shipping cost defined in the shown code? If you havent added it, you can add it to a hidden input.
Just be sure to calculate it again in the backend. The user might edit it
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, i'm currently is developing a website. The website that i develop has a create new booking, so when the admin want to create the new booking, admin must fill the name of the user, and input the item that user want, with how much quantity that user want, and shipping cost. So the total price would be
Total price = (price * quantity) + shipping cost
How can i do that??
The javascript :
calculateAndShowPrice: function (qtt) {
var itemService = this.getSelectedItemObject();
var self = this;
if (!this.isDefinedAndNotEmpty(qtt)) {
$("#inQtt").val(1);
qtt = 1;
}
itemService.getCalculatedPrice(function (totalPrice) {
self.showPrice(totalPrice);
}, function () {
var totalPrice = self.getHiddenPrice() * qtt;
self.showPrice(totalPrice);
});
}
The blade file :
<div class="guest-wrapper d-flex justify-content-between align-items-center cls-detail-item">
<div class="flex-grow-1">
<label id="lblQtt">{{ __('Quantity') }}</label>
</div>
<div class="flex-shrink-0">
<div class="input-number-group">
<span class="input"><input id="inQtt" type="number" v-model="quantity"
min="1" /></span>
</div>
</div>
</div>
<div class="guest-wrapper d-flex justify-content-between align-items-center cls-detail-item">
<div class="flex-grow-1">
<label id="lblSC">{{ __('Shipping Cost') }}</label>
</div>
<div class="flex-shrink-0">
<div class="input-number-group">
<span class="input"><input id="inpSC" type="number" v-model="quantity"
min="1" /></span>
</div>
</div>
</div>
@nicho Can you try this . This occurs with JS . It thinks we are asking to concatenate the variables. So we must be sure of typecasting them when it comes to arithmatic functions.
var qtt = parseInt($('#inQtt').val());
var price = 45000
var sc =parseInt( $('#inpSC').val());
var totalPrice = (price * qtt) + sc;
alert(totalPrice);
Please or to participate in this conversation.