Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Free Shipping Per Product - Exclude AK & HA ?


Roaddoctor

Recommended Posts

Free Shipping Per Product on 2.3.3.4

Works well but I need exclude Alaska and Hawaii from free shipping. I've tried but cant make it work. I appreciate any assistance.

 

checkout_shipping.php

Having this code bock

 

// PRODUCTS SHIP FREE START
// get free shipping before calculating cart weight and count
// load all enabled shipping modules - moved below
/*
require(DIR_WS_CLASSES . 'shipping.php');
$shipping_modules = new shipping;
*/
$free_shipping = false;
$products_ship_free = false;
$free_pass = false;
$ship_free_count = 0;
if ((defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') || (defined('MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE') && MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE == 'true'))
{
switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION)
{
case 'national': if ($order->delivery['country_id'] == STORE_COUNTRY) $free_pass = true;
break;
case 'international': if ($order->delivery['country_id'] != STORE_COUNTRY) $free_pass = true;
break;
case 'both': $free_pass = true;
break;
}
if($free_pass == true)
{
if (defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true' && $order->info['total'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER)
$free_shipping = true;
elseif ( defined('MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE') && (MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE == 'true'))
{
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++)
{
if ($products[$i]['ship_free'] == '1')
 {
 $ship_free_count += $products[$i]['quantity'];
 $total_weight -= $products[$i]['weight']*$products[$i]['quantity'];
 $total_count -= $products[$i]['quantity'];
 }
}
if ($total_weight == 0 && $total_count == 0)
{
$products_ship_free = true;
$free_shipping = true;
}
}
if ($free_shipping == true || $products_ship_free == true || $ship_free_count > 0)
include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_shipping.php');
}
}


// load all enabled shipping modules
require(DIR_WS_CLASSES . 'shipping.php');
$shipping_modules = new shipping;
// PRODUCTS SHIP FREE END

 

I found a fix for the old 2.2 version, but need help applying the same or similar to the above

 

// for free ship AK HA fix
	 if ($order->delivery['country_id'] != STORE_COUNTRY && FREE_SHIPPING_TO_ALL_COUNTRIES == "false") {
 $free_shipping = false;
} elseif ($order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "Hawaii"){
 $free_shipping = false;
} elseif ($order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "Alaska"){
 $free_shipping = false;
}
// End for free ship AK HA fix

 

I tried several different variants of the fix in different spots but without luck. Anyone smarter than me care to throw me a bone?

 

Thank you

Dave

-Dave

Link to comment
Share on other sites

Hi

 

You could try adding it in with a little edit before the line:

 

if($free_pass == true)

 

so that it switched free_pass to false

 

// for free ship AK HA fix
   if ($order->delivery['country_id'] != STORE_COUNTRY && FREE_SHIPPING_TO_ALL_COUNTRIES == "false") {
	 $free_pass = false;
} elseif ($order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "Hawaii"){
	 $free_pass = false;
} elseif ($order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "Alaska"){
	 $free_pass = false;
}
// End for free ship AK HA fix

 

Alternatively try putting your original AK/HA fix in above the line

 

if ( (tep_count_shipping_modules() > 0) || ($free_shipping == true) ) {

Link to comment
Share on other sites

@@MrPhil thank you sir... Well I'm a bit perplexed. Will not work.

 

I have 3 variants of the "fix" in 3 places in this block, and none are working. Time to look elsewhere in the code I guess.

 

// PRODUCTS SHIP FREE START
// get free shipping before calculating cart weight and count
// load all enabled shipping modules - moved below
/*
require(DIR_WS_CLASSES . 'shipping.php');
$shipping_modules = new shipping;
*/

$free_shipping = false;
$products_ship_free = false;
$free_pass = false;
$ship_free_count = 0;
if ((defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') || (defined('MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE') && MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE == 'true'))
{
switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION)
{
case 'national': if ($order->delivery['country_id'] == STORE_COUNTRY) { $free_pass = true;

// for free ship AK HI fix
} elseif ($order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "HI"){
$free_pass = false;
} elseif ($order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "AK"){
$free_pass = false;
}
// End for free ship AK HI fix*/

break;
case 'international': if ($order->delivery['country_id'] != STORE_COUNTRY) $free_pass = true;
break;
case 'both': $free_pass = true;
break;
}


// for free ship AK HI fix
if ($order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "HI"){
$free_pass = false;
} elseif ($order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "AK"){
$free_pass = false;
}
// End for free ship AK HI fix


if($free_pass == true)
{
if (defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true' && $order->info['total'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER)
$free_shipping = true;
elseif ( defined('MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE') && (MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE == 'true'))
{
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++)
{
if ($products[$i]['ship_free'] == '1')
{
$ship_free_count += $products[$i]['quantity'];
$total_weight -= $products[$i]['weight']*$products[$i]['quantity'];
$total_count -= $products[$i]['quantity'];
}
}
if ($total_weight == 0 && $total_count == 0)
{
$products_ship_free = true;
$free_shipping = true;
}
}
if ($free_shipping == true || $products_ship_free == true || $ship_free_count > 0)
include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_shipping.php');
}
}

// load all enabled shipping modules
require(DIR_WS_CLASSES . 'shipping.php');
$shipping_modules = new shipping;

// PRODUCTS SHIP FREE END

// process the selected shipping method
if ( isset($HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'process') && isset($HTTP_POST_VARS['formid']) && ($HTTP_POST_VARS['formid'] == $sessiontoken) ) {
if (!tep_session_is_registered('comments')) tep_session_register('comments');
if (tep_not_null($HTTP_POST_VARS['comments'])) {
$comments = tep_db_prepare_input($HTTP_POST_VARS['comments']);
}

if (!tep_session_is_registered('shipping')) tep_session_register('shipping');


// for free ship AK HI fix
if ($order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "HI"){
$free_shipping = false;
} elseif ($order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "AK"){
$free_shipping = false;
}
// End for free ship AK HI fix


if ( (tep_count_shipping_modules() > 0) || ($free_shipping == true) ) {
if ( (isset($HTTP_POST_VARS['shipping'])) && (strpos($HTTP_POST_VARS['shipping'], '_')) ) {
$shipping = $HTTP_POST_VARS['shipping'];

list($module, $method) = explode('_', $shipping);
if ( is_object($$module) || ($shipping == 'free_free') ) {
if ($shipping == 'free_free') {
$quote[0]['methods'][0]['title'] = FREE_SHIPPING_TITLE;
$quote[0]['methods'][0]['cost'] = '0';
} else {
$quote = $shipping_modules->quote($method, $module);
}
if (isset($quote['error'])) {
tep_session_unregister('shipping');
} else {
if ( (isset($quote[0]['methods'][0]['title'])) && (isset($quote[0]['methods'][0]['cost'])) ) {
$shipping = array('id' => $shipping,
'title' => (($free_shipping == true) ? $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')'),
'cost' => $quote[0]['methods'][0]['cost']);

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
}
} else {
tep_session_unregister('shipping');
}
}
} else {
$shipping = false;

tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
}

// get all available shipping quotes
$quotes = $shipping_modules->quote();

-Dave

Link to comment
Share on other sites

I'm surprised that you're not getting a PHP syntax error (are you suppressing errors?). You have

if ((defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') || (defined('MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE') && MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE == 'true'))
{
switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION)
{
case 'national': if ($order->delivery['country_id'] == STORE_COUNTRY) { $free_pass = true;

// for free ship AK HI fix
} elseif ($order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "HI"){
$free_pass = false;
} elseif ($order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "AK"){
$free_pass = false;
}
// End for free ship AK HI fix*/

break;

which is an elseif in the middle of a case. Maybe you want

if ((defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') || (defined('MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE') && MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE == 'true'))
{
switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION)
{
case 'national': if ($order->delivery['country_id'] == STORE_COUNTRY) { $free_pass = true;

// for free ship AK HI fix
if ($order->delivery['country_id'] == STORE_COUNTRY &&
 ($order->delivery['state'] == "HI" || $order->delivery['state'] == "AK")){
$free_pass = false;
}
// End for free ship AK HI fix*/

break;

 

I haven't looked at the rest of the code yet. BTW, if you want free shipping for the 48 states only, consider Puerto Rico, Guam, and other territories, etc. that are part of the US but you might not want to ship free to, due to distance.

Edited by MrPhil
Link to comment
Share on other sites

@@MrPhil I believe your code is spot on perfect and exactly where it should work. But, my luck, not working. It has to be something else elsewhere hijacking... this shop is pretty darn modified with several shipping tweaks going on.

 

Thanks for the inputs, and Bob as well. At least I know it "should" work

-Dave

Link to comment
Share on other sites

Here is the whole section if anyone has any insight

 

<?php
/*
$Id$
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2012 osCommerce
Released under the GNU General Public License
*/
require('includes/application_top.php');
require('includes/classes/http_client.php');
// if the customer is not logged on, redirect them to the login page
if (!tep_session_is_registered('customer_id')) {
$navigation->set_snapshot();
tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
}
// if there is nothing in the customers cart, redirect them to the shopping cart page
if ($cart->count_contents() < 1) {
tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
}
// if no shipping destination address was selected, use the customers own address as default
if (!tep_session_is_registered('sendto')) {
tep_session_register('sendto');
$sendto = $customer_default_address_id;
} else {
// verify the selected shipping address
if ( (is_array($sendto) && empty($sendto)) || is_numeric($sendto) ) {
 $check_address_query = tep_db_query("select count(*) as total from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' and address_book_id = '" . (int)$sendto . "'");
 $check_address = tep_db_fetch_array($check_address_query);
 if ($check_address['total'] != '1') {
 $sendto = $customer_default_address_id;
 if (tep_session_is_registered('shipping')) tep_session_unregister('shipping');
 }
}
}
require(DIR_WS_CLASSES . 'order.php');
$order = new order;
// register a random ID in the session to check throughout the checkout procedure
// against alterations in the shopping cart contents
if (!tep_session_is_registered('cartID')) {
tep_session_register('cartID');
} elseif (($cartID != $cart->cartID) && tep_session_is_registered('shipping')) {
tep_session_unregister('shipping');
}
$cartID = $cart->cartID = $cart->generate_cart_id();
// if the order contains only virtual products, forward the customer to the billing page as
// a shipping address is not needed
if ($order->content_type == 'virtual') {
if (!tep_session_is_registered('shipping')) tep_session_register('shipping');
$shipping = false;
$sendto = false;
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
$total_weight = $cart->show_weight();
$total_count = $cart->count_contents();
// PRODUCTS SHIP FREE START
// get free shipping before calculating cart weight and count
// load all enabled shipping modules - moved below
/*
require(DIR_WS_CLASSES . 'shipping.php');
$shipping_modules = new shipping;
*/
$free_shipping = false;
$products_ship_free = false;
$free_pass = false;
$ship_free_count = 0;
if ((defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') || (defined('MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE') && MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE == 'true'))
{
switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION)
{
case 'national': if ($order->delivery['country_id'] == STORE_COUNTRY) $free_pass = true;
// for free ship AK HI fix
if ($order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "HI" ||
$order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "AK"){
$free_pass = false;
}
// End for free ship AK HI fix
break;
case 'international': if ($order->delivery['country_id'] != STORE_COUNTRY) $free_pass = true;
break;
case 'both': $free_pass = true;
break;
}
if($free_pass == true)
{
if (defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true' && $order->info['total'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER)
$free_shipping = true;
elseif ( defined('MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE') && (MODULE_ORDER_TOTAL_PRODUCTS_SHIP_FREE == 'true'))
{
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++)
{
if ($products[$i]['ship_free'] == '1')
 {
 $ship_free_count += $products[$i]['quantity'];
 $total_weight -= $products[$i]['weight']*$products[$i]['quantity'];
 $total_count -= $products[$i]['quantity'];
 }
}
if ($total_weight == 0 && $total_count == 0)
{
$products_ship_free = true;
$free_shipping = true;
}
}
if ($free_shipping == true || $products_ship_free == true || $ship_free_count > 0)
include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_shipping.php');
}
}
// load all enabled shipping modules
require(DIR_WS_CLASSES . 'shipping.php');
$shipping_modules = new shipping;
// PRODUCTS SHIP FREE END
// process the selected shipping method
if ( isset($HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'process') && isset($HTTP_POST_VARS['formid']) && ($HTTP_POST_VARS['formid'] == $sessiontoken) ) {
if (!tep_session_is_registered('comments')) tep_session_register('comments');
if (tep_not_null($HTTP_POST_VARS['comments'])) {
 $comments = tep_db_prepare_input($HTTP_POST_VARS['comments']);
}
if (!tep_session_is_registered('shipping')) tep_session_register('shipping');
if ( (tep_count_shipping_modules() > 0) || ($free_shipping == true) ) {
 if ( (isset($HTTP_POST_VARS['shipping'])) && (strpos($HTTP_POST_VARS['shipping'], '_')) ) {
 $shipping = $HTTP_POST_VARS['shipping'];
 list($module, $method) = explode('_', $shipping);
 if ( is_object($$module) || ($shipping == 'free_free') ) {
	 if ($shipping == 'free_free') {
	 $quote[0]['methods'][0]['title'] = FREE_SHIPPING_TITLE;
	 $quote[0]['methods'][0]['cost'] = '0';
	 } else {
	 $quote = $shipping_modules->quote($method, $module);
	 }
	 if (isset($quote['error'])) {
	 tep_session_unregister('shipping');
	 } else {
	 if ( (isset($quote[0]['methods'][0]['title'])) && (isset($quote[0]['methods'][0]['cost'])) ) {
		 $shipping = array('id' => $shipping,
						 'title' => (($free_shipping == true) ? $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')'),
						 'cost' => $quote[0]['methods'][0]['cost']);
		 tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
	 }
	 }
 } else {
	 tep_session_unregister('shipping');
 }
 }
} else {
 $shipping = false;

 tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
}
// get all available shipping quotes
$quotes = $shipping_modules->quote();

-Dave

Link to comment
Share on other sites

This code is atrocious. What is $free_pass versus $free_shipping? Without comments, it's hard to tell what the author's intent is.

 

First of all, figure out what the various $free_* variables (flags) are supposed to represent. Then make sure they are properly set, including special conditions for outside the US 48 states (consider PR, GU, etc. as included in no free shipping). Maybe you're only clearing $free_pass for AK and HI when you should also/instead be clearing $free_shipping.

 

As I said before, I stopped looking at that one place where I gave the code correction. There are likely to be other errors in the code.

Link to comment
Share on other sites

Thanks Phil, sorry things weren't commented well - to many mods mish-mashing and haven't cleaned up yet.. I managed to get it sorted though. All credit to mattjt83 for the help. Much appreciated.

 

case 'national': if ($order->delivery['country_id'] == STORE_COUNTRY) $free_pass = true;
// for free ship AK HI fix
/**
if ($order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "HI" || $order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['state'] == "AK"){ $free_pass = false; } check by $order->delivery['zone_id'] instead
2 = AK
21 = HI
*/
if ( $order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['zone_id'] == 21 || $order->delivery['country_id'] == STORE_COUNTRY && $order->delivery['zone_id'] == 2 ){ $free_pass = false; }
// End for free ship AK HI fix
break;

-Dave

Link to comment
Share on other sites

For future readers/users of the code, bear in mind that your "AK" might very well not be id "2" as per:

 

$order->delivery['zone_id'] == 2

 

Same for HI.

 

Never compare apples to oranges, only apples to apples.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...