Post by ktae11 » Thu Aug 24, 2017 11:11 pm

Hello.

Im totally beginner.

Im using 2.3.0.2 opencart

I would like to add a "free shipping teaser" in my store as shown in image in the link

https://ibb.co/eeuE95

Logic:

If customer buys items with total value equal or above $64,
then a message will appear in dropdown cart "You have free shipping!"
else a message will appear "You are $xx away from free shipping!"


Here is the code from cart.tpl

<div id="cart" class="clearfix pull-right dropdown">
<div data-toggle="dropdown" data-loading-text="<?php echo $text_loading; ?>" class="dropdown-toggle">
<div class="cart-inner">
<a href="">
<?php echo $objlang->get("text_heading_title"); ?>
<span id="cart-total" class="cart-total radius-6x "><?php echo substr($text_items, 0, strpos($text_items, ' ')+1); ?></span>
<?php
$res = explode("-", $text_items);
?>

</a>
</div>
</div>
<ul class="dropdown-menu pull-right">
<?php if ($products || $vouchers) { ?>
<li>
<table class="table first">
<?php foreach ($products as $product) { ?>
<tr>
<td class="text-left image"><?php if ($product['thumb']) { ?>
<a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-thumbnail" /></a>
<?php } ?></td>
<td class="text-left"><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a>
<?php if ($product['option']) { ?>
<?php foreach ($product['option'] as $option) { ?>
<br />
- <small><?php echo $option['name']; ?> <?php echo $option['value']; ?></small>
<?php } ?>
<?php } ?>
<?php if ($product['recurring']) { ?>
<br />
- <small><?php echo $text_recurring; ?> <?php echo $product['recurring']; ?></small>
<?php } ?></td>
<td class="text-right">x <?php echo $product['quantity']; ?></td>
<td class="text-right"><?php echo $product['total']; ?></td>
<td class="text-right"><button type="button" onclick="cart.remove('<?php echo $product['cart_id']; ?>');" title="<?php echo $button_remove; ?>" class="btn btn-danger btn-xs"><i class="fa fa-times"></i></button></td>
</tr>
<?php } ?>
<?php foreach ($vouchers as $voucher) { ?>
<tr>
<td class="text-center"></td>
<td class="text-left"><?php echo $voucher['description']; ?></td>
<td class="text-right">x&nbsp;1</td>
<td class="text-right"><?php echo $voucher['amount']; ?></td>
<td class="text-center text-danger"><button type="button" onclick="voucher.remove('<?php echo $voucher['key']; ?>');" title="<?php echo $button_remove; ?>" class="btn btn-danger btn-xs"><i class="fa fa-times"></i></button></td>
</tr>
<?php } ?>
</table>
</li>
<li>
<div>
<table class="table table-bordered">
<?php foreach ($totals as $total) { ?>
<tr>
<td class="text-right"><strong><?php echo $total['title']; ?></strong></td>
<td class="text-right"><?php echo $total['text']; ?></td>
</tr>
<?php } ?>
</table>
<p class="text-right"><a href="<?php echo $cart; ?>"><span class="btn btn-primary"><?php echo $text_cart; ?></span></a>&nbsp;&nbsp;&nbsp;<a href="<?php echo $checkout; ?>"><span class="btn btn-default"><?php echo $text_checkout; ?></span></a></p>
</div>
</li>
// Code for free shipping is inserted here //
<?php } else { ?>
<li>
<p class="text-center"><?php echo $text_empty; ?></p>
</li>
<?php } ?>
</ul>
</div>




Im inserting this code but still get errors.
No luck at all.


<li>
<?php
$t = 64;
$free = $t - $total;

if ($free > "0") {
echo "You are ", $free['text'], "away from FREE SHIPPING!";
} else {
echo "You have free shipping!";
}
?>
</li>



Please help.
Thank you in advance.

Newbie

Posts

Joined
Fri May 19, 2017 9:43 am

Post by simonpieman » Tue Aug 29, 2017 5:28 am

try something like this (apologies i didnt have long on 2.1.0.2 so its pretty basic but will give you some ideas)

<?php
$t = 64;
$totalnow = ltrim($total['text'], '$');
$totalnow = (int)$totalnow;
$free = $t - $totalnow;

if ($free > "0") {
echo "<li>You are ", $free, "away from FREE SHIPPING!</li>";
} else {
echo "<li>You have free shipping!</li>";
}
?>

Go the All Blacks!


New member

Posts

Joined
Thu Jul 02, 2015 8:58 am
Location - NZ - Auckland

Post by ktae11 » Sat Sep 02, 2017 1:11 am

simonpieman wrote:
Tue Aug 29, 2017 5:28 am
try something like this (apologies i didnt have long on 2.1.0.2 so its pretty basic but will give you some ideas)

<?php
$t = 64;
$totalnow = ltrim($total['text'], '$');
$totalnow = (int)$totalnow;
$free = $t - $totalnow;

if ($free > "0") {
echo "<li>You are ", $free, "away from FREE SHIPPING!</li>";
} else {
echo "<li>You have free shipping!</li>";
}
?>
Thank you simonpieman!

You gave me a hint.

I have just used

filter_var($total['text'], FILTER_SANITIZE_NUMBER_INT);

Newbie

Posts

Joined
Fri May 19, 2017 9:43 am
Who is online

Users browsing this forum: No registered users and 24 guests