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.
Hi All,
My customer is currently shipping to the US only. I'm trying to add Canada shipping to this custom shipping script. I've tried a number of ways, none of which worked.
Can someone help with this? Here's the base script.
<?php // +-- // | All custom shipping scripts work in the same way. A global // | variable named 'ecom.customship' contains the following PHP // | array. Array keys with value info: // | // | weight => Total weight of items being shipped. // | total => Subtotal of items being shipped. // | quantity => Quantity of items being shipped. // | stateprov => Ship to state/province. // | country => Ship to country. // | postalcode => Ship to postal code. // | rescom => Ship to residential/commercial status. // | shipstateprov => Ship origin state/province. // | shipcountry => Ship origin country. // | shipzip => Ship origin postal code. // | packages => An array containing all packages with // | each package defined in it's own array // | with keys: length, width, height, weight. // | delinfo => Delivery information array. // | delitems => An array containing all items with // | each item id as a key and the item quantity // | as a value. // | // | This script must set a global variable named // | 'ecom.customship_response' which is an array in the // | following format: // | // | method name => amount // | // | NOTE: Do not print anything within custom shipping // | scripts. They are designed only to return names and // | prices for custom shipping methods. // | // | This script is a Calculation On Total Item Quantity script that // | returns a prices based on total item quantity. // +-- $info = $this->globals('ecom.customship'); if (($info['quantity'] >= 1) && ($info['quantity'] <= 6)){ $method = 'USPS Shipping Costs'; $total = '8.00'; $custom = array($method => $total); } else { $method = 'USPS Shipping Costs'; $total = '14.00'; $custom = array($method => $total); } $this->globals('ecom.customship_response',$custom); ?>
Any help would be greatly appreciated.
Thanks, Steve
Offline
This is the code that I use. It does a little more than you asked for but it might give you some ideas.
<?php
// +--
// | All custom shipping scripts work in the same way. A global
// | variable named 'ecom.customship' contains the following PHP
// | array. Array keys with value info:
// |
// | weight => Total weight of items being shipped.
// | total => Subtotal of items being shipped.
// | quantity => Quantity of items being shipped.
// | stateprov => Ship to state/province.
// | country => Ship to country.
// | postalcode => Ship to postal code.
// | rescom => Ship to residential/commercial status.
// | shipstateprov => Ship origin state/province.
// | shipcountry => Ship origin country.
// | shipzip => Ship origin postal code.
// | packages => An array containing all packages with
// | each package defined in it's own array
// | with keys: length, width, height, weight.
// |
// | This script must set a global variable named
// | 'ecom.customship_response' which is an array in the
// | following format:
// |
// | method name => amount
// |
// | NOTE: Do not print anything within custom shipping
// | scripts. They are designed only to return names and
// | prices for custom shipping methods.
// |
// | This script is a n incremental - cost per item script
// +--
$info = $this->globals('ecom.customship');
// Declare the variables
$item_quantity = $info['quantity'];
$ship_meth_name = 'Standard Shipping';
$ship_total = 0.00;
$ship_meth_name1 = 'Fast Forward (3 Day)';
$ship_total1 = (5.00 * $item_quantity);
$ship_meth_name2 = 'Canada';
$ship_total2 = (7.00 * $item_quantity);
$ship_meth_name3 = 'Alaska & Hawaii';
$ship_total3 = (7.00 * $item_quantity);
// Determine Standard Shipping
if ($item_quantity >= 500) {
$ship_total = $item_quantity * 0.35;
} elseif($item_quantity >= 120) {
$ship_total = $item_quantity * 0.65;
} elseif($item_quantity >= 24) {
$ship_total = $item_quantity * 0.85;
} elseif($item_quantity >= 7) {
$ship_total = $item_quantity * 0.85;
} else {
$ship_total = 6.00;
}
// Setup the array
if ($info['country'] == 'Canada') {
$custom = array($ship_meth_name2 => $ship_total2);
} elseif ($info['stateprov'] == 'Alaska' || $info['stateprov'] == 'Hawaii') {
$custom = array($ship_meth_name3 => $ship_total3);
} else {
$custom = array($ship_meth_name => $ship_total, $ship_meth_name1 => $ship_total1);
}
// Close it out
$this->globals('ecom.customship_response',$custom);
?>
Offline
Thank you. I'll give it a try.
Steve
Offline