Change 'Shipping' to 'Delivery' in Simple Cart Order Summary
3 posts by 2 authors in: Forums > CMS Builder
Last Post: September 7 (RSS)
Where is 'name' set in the code below?
Can it be easily changed without screwing-up anything else? Thanks!
<?php if ($extraLineItems): ?>
<?php foreach ($extraLineItems as $extraLineField => $extraLineItem): ?>
<div class="row">
<div class="col-6">
<p class="mb-0"><?php echo htmlencode($extraLineItem['name']); ?></p>
</div>
<div class="col-6">
<p class="text-end mb-0"><?php echo sc_moneyFormat($extraLineItem['TOTAL']); ?></p>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
Hi Jeff,
It looks like $extraLineItems is an array of fieldnames to arrays. So name is defined in $extraLineItems.
I'm not familiar with that exact piece of code but if you want to override output for a single value you can do it like this
<p class="mb-0">
<?php
if ($extraLineItem['name'] === 'previous value') {
echo "new value";
}
else {
echo htmlencode($extraLineItem['name']);
}
?>
</p>
Or you can use the new match expression in PHP 8.0+ which can be simpler than long if/if else/else statements:
<p class="mb-0">
<?php
echo match ($extraLineItem['name']) {
'old value 1' => 'new value 1',
'another value' => 'new value 2',
default => htmlencode($extraLineItem['name']),
};
?>
</p>
Hope that helps!
interactivetools.com
By JeffC - September 7
Thanks for your help Dave.
Thanks for pointing me in the right direction. I found a different solution. In customCart.php
function sc_addShipping($cartItems) {
$shippingTotal = 0;
foreach ($cartItems as $cartItem) {
$shippingTotal += @$cartItem['shipping'] * @$cartItem['quantity'];
foreach ($cartItem['OPTIONS'] as $option) {
$shippingTotal += @$option['shipping'] * @$cartItem['quantity'];
}
}
return array( 'name' => 'Shipping', 'TOTAL' => $shippingTotal );
}
Changed:
return array( 'name' => 'Shipping', 'TOTAL' => $shippingTotal );
to
return array( 'name' => 'Delivery', 'TOTAL' => $shippingTotal );
Using the same method I changed TAX to VAT.
function sc_addTax($cartItems) {…
return array( 'name' => "VAT ($taxPercentage%)", 'TOTAL' => $taxTotal );
…}