You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.
NOTE: This post was created on 2023-04-20 on the Kryptronic eCommerce Community facebook page, which has been replaced with this forum. All facebook support content was migrated into this forum in April 2024.
Bruce:
Hi,
I have an inner London surcharge in a custom shipping script but I need it to look for a positive value in the shipping charge before adding the surcharge and to skip if the value of shipping is 00.00
Can some one have a look at this please.
Begining of Code...
// +--
// | Surcharge
// +--
$shipquantity = $info['quantity'];
$shippostcode = $info['postalcode'];
$ordertotal = $info['total'];
$shippostcode = strtoupper($shippostcode);
$postcode = preg_replace( '/[^a-z0-9]/i', '', $shippostcode );
if ( in_array( strlen( $postcode ), array( 5, 6, 7 ) ) ) {$postcode = substr( $postcode, 0, -3 );}
$dosurcharge = 0;
if (preg_match('/EC\d{1,2}/i', $postcode)) {$dosurcharge++;}
elseif (preg_match('/NW\d{1,2}/i', $postcode)) {$dosurcharge++;}
elseif (preg_match('/SE\d{1,2}/i', $postcode)) {$dosurcharge++;}
elseif (preg_match('/SW\d{1,2}/i', $postcode)) {$dosurcharge++;}
elseif (preg_match('/WC\d{1,2}/i', $postcode)) {$dosurcharge++;}
elseif (preg_match('/E\d{1,2}/i', $postcode)) {$dosurcharge++;}
elseif (preg_match('/N\d{1,2}/i', $postcode)) {$dosurcharge++;}
if ($info['stateprov'] != 'London') {$dosurcharge = 0;}
if (!(empty($dosurcharge))) {
$method .= ' including Inner London Surcharge';
$total += 1.75;
} // End of if statement.
.....End of Code
Kryptronic:
Assuming you've defined and set $total above the code you posted, this line:
if (!(empty($dosurcharge))) {
Should change to:
if ((!(empty($dosurcharge))) && (!(empty($total)))) {
So that the $surcharge is only added if the $total is greater than zero.
Bruce:
My custom shipping script sections all end like this, I assume they are defining the $total ?
// Rest of the world
$method = 'For Delivery Quote, contact Westfield4Schools on 0121 233 1671.';
$total = '00.00';
$custom = array($method => $total);
}
//
Bruce:
OK this didn't work.
What code am I looking for to define $totals ?
Offline