Conditional shipping option?
Is there a way I can control which shipping options are presented based on the shipping costs of FedEx.
Normally we only offer FedEx for International. Shipping averages around $23. However for some destinations, the shipping can be $50-70. For FedEx costs > $40, I would like the USPS first Class option to appear with the FedEx option. For FedEx costs < $40, only the FedEx option should appear.
The reason for this is that USPS FC international is slow and unreliable and we want to avoid it unless the FedEx cost is simply too high.
Re: Conditional shipping option?
This is what FedEx and USPS shows at 13oz ...
Code:
FedEx (1 x 0.81lbs) (International Priority) |
$75.18 |
FedEx (1 x 0.81lbs) (International Economy) |
$71.47 |
FedEx (1 x 0.81lbs) (Fedex Ground (2 days)) |
$19.70 |
United States Postal Service (1 Boxes) (0 lbs, 13 oz) (First-Class Mail® International Large Envelope) |
$5.25 |
United States Postal Service (1 Boxes) (0 lbs, 13 oz) (First-Class Package International Service™) |
$9.50 |
United States Postal Service (1 Boxes) (0 lbs, 13 oz) (Priority Mail International® Flat Rate Envelope) |
$19.95 |
United States Postal Service (1 Boxes) (0 lbs, 13 oz) (Priority Mail International®) |
$27.40 |
United States Postal Service (1 Boxes) (0 lbs, 13 oz) (Priority Mail Express International™ Flat Rate Envelope) |
$34.95 |
United States Postal Service (1 Boxes) (0 lbs, 13 oz) (Priority Mail Express International™) |
$35.48 |
United States Postal Service (1 Boxes) (0 lbs, 13 oz) (Priority Mail International® Medium Flat Rate Box) |
$40.95 |
United States Postal Service (1 Boxes) (0 lbs, 13 oz) (Priority Mail International® Large Flat Rate Box) |
$53.95 |
United States Postal Service (1 Boxes) (0 lbs, 13 oz) (Global Express Guaranteed® (GXG)) |
$55.41 |
United States Postal Service (1 Boxes) (0 lbs, 13 oz) (USPS GXG™ Envelopes) |
$55.41 |
United States Postal Service (1 Boxes) (0 lbs, 13 oz) (Priority Mail Express International™ Flat Rate Boxes) |
$64.95 |
What Ship To, Ship From and Weight are you testing with?
What do you want to see differently on these costs?
Re: Conditional shipping option?
The weight is always 2lbs or less, and typically 13 oz.
The from is USA, the to is any international destination.
If price > $40, show USPS first class and FedEx option, else show FedEx option on the shopping cart page and on the checkout page.
Said differently, if price <=$40, only show FedEx option
Re: Conditional shipping option?
Try this ...
Customize the file:
/includes/modules/shipping/fedexwebservices.php
with the code in RED:
Code:
$methods = array();
// bof: check FedEx for > 40.00
$_SESSION['usps_first_class'] = 0;
foreach ($response->RateReplyDetails as $rateReply) {
Code:
$methods[] = array('id' => str_replace('_', '', $rateReply->ServiceType),
'title' => ucwords(strtolower(str_replace('_', ' ', $rateReply->ServiceType))) . $transitTime,
'cost' => $cost + (strpos($this->types[$rateReply->ServiceType]['handling_fee'], '%') ? ($cost * (float)$this->types[$rateReply->ServiceType]['handling_fee'] / 100) : (float)$this->types[$rateReply->ServiceType]['handling_fee']));
$chk_cost = ($cost + (strpos($this->types[$rateReply->ServiceType]['handling_fee'], '%') ? ($cost * (float)$this->types[$rateReply->ServiceType]['handling_fee'] / 100) : (float)$this->types[$rateReply->ServiceType]['handling_fee']));
if ($_SESSION['usps_first_class'] == 0 || $chk_cost < $_SESSION['usps_first_class']) {
$_SESSION['usps_first_class'] = $chk_cost;
}
//echo 'FedEx Cost Calc: ' . $chk_cost . ' $_SESSION[usps_first_class]: ' . $_SESSION['usps_first_class'] . '<br><br>';
// bof: check FedEx for > 40.00
}
}
}
$this->quotes['methods'] = $methods;
Then customize the file:
/includes/modules/shipping/usps.php
Code:
if ($this->usps_countries == 'US' && MODULE_SHIPPING_USPS_FIRST_CLASS_FILTER_US == 'True' && preg_match('#First\-Class#i', $type) && $cnt_first > 1) continue;
// bof: check FedEx for > 40.00
//echo 'USPS FedEx $_SESSION[usps_first_class]: ' . $_SESSION['usps_first_class'] . ' $type: ' . $type . '<br>';
//echo 'USPS $type_rebuilt: ' . $type_rebuilt . '<br>';
if (preg_match('#(first-class)#i', $type_rebuilt) && $_SESSION['usps_first_class'] > 40) {
$methods[] = array('id' => $type_rebuilt,
'title' => $title,
'cost' => $cost,
);
}
// eof: check FedEx for > 40.00
} else {
//echo 'MISSING! USPS $type: ' . $type . (in_array($type, $this->typeCheckboxesSelected) ? ' YES' : ' NO') . ' $method: ' . $method . ' $usps_shipping_weight: ' . $usps_shipping_weight . ' $minweight: ' . $minweight . ' $maxweight: ' . $maxweight . '<br>';
}
} // end for $i to $PackageSize
if (sizeof($methods) == 0) return false;
Be sure that on the Modules ... Shipping ... that you set a Sort Order on FedEx such as 10 and on USPS a Sort Order of 20 so that FedEx runs before USPS for this to work ...
Re: Conditional shipping option?
Ajeh,
That seems to work...thanks.
When both FedEx and USPS options show, the USPS option is by default selected. Is there a way I can make FedEx the default, or better yet, neither checked?
Also, the message for USPS is:
United States Postal Service (First-Class Package International Service™)
How can I change this to:
United States Postal Service (First-Class 7-20 days)
Can a hyperlink be inserted into that text?
Re: Conditional shipping option?
I spoke to soon.
For the US, we offer only USPS priority. When I checked a US location, the shopping cart no longer listed a value for USPS priority....it was just missing with no rate estimate at all.
This is most likely my fault for lack of full disclosure
USA locations: USPS priority only
International locations: FedEx<$40, then FedEx only. FedEx>=$40, USPS FC and FedEx
Re: Conditional shipping option?
You could use the CUSTOM setting:
Quote:
USPS Domestic Transit Time Calculation Mode
Select from the following the USPS options.
note: NEW and OLD will add additional time to quotes. CUSTOM allows your custom shipping days.
CUSTOM
NEW
OLD
and show the days by turning on the:
Quote:
Display transit time
Then, in the function parseIntlTransitTimeResults($Package, $service) you will see where the days can be customized ...
Re: Conditional shipping option?
Quote:
Originally Posted by
split63
I spoke to soon.
For the US, we offer only USPS priority. When I checked a US location, the shopping cart no longer listed a value for USPS priority....it was just missing with no rate estimate at all.
This is most likely my fault for lack of full disclosure
USA locations: USPS priority only
International locations: FedEx<$40, then FedEx only. FedEx>=$40, USPS FC and FedEx
The name to allow can be changed in the:
/includes/modules/shipping/usps.php
Code:
if (preg_match('#Priority Mail International#i', $type_rebuilt) && $_SESSION['usps_first_class'] > 40) {
while the session variable is reading usps_first_class it is just a marker so its name is not important, but for clarity you might change it in both files to:
$_SESSION['usps_priority']
that is up to you ...
Re: Conditional shipping option?
Are you wanting USPS to show when the Ship to is to a US address? Or just on those Ship to for International addresses?
Re: Conditional shipping option?
Quote:
Originally Posted by
Ajeh
Are you wanting USPS to show when the Ship to is to a US address? Or just on those Ship to for International addresses?
USA locations: USPS priority only
International locations: FedEx<$40, then FedEx only. FedEx>=$40, USPS FC and FedEx