Zen Cart Logo
Forums / General Questions / Restrict coupon code on PO Box shipping addresses

Restrict coupon code on PO Box shipping addresses

Views: 507

Results 1 to 3 of 3
11 Jan 2016, 11:55 PM
#1
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
520
Plugin Contributions:
2

Restrict coupon code on PO Box shipping addresses

I'm trying to restrict a coupon code that gives free shipping to PO Box shipping addresses. I ship with three carriers UPS, FedEx, and USPS. I customized UPS and FedEx shipping modules to disable using the following statement:

      if ( preg_match('/PO BOX/si', $order->delivery['street_address'])) { 
                $this->enabled = false;
		$po_box_address = true;
      } else if ( preg_match('/POBOX/si', $order->delivery['street_address'])) { 
                $this->enabled = false;
		$po_box_address = true;
      } else if ( preg_match('/P\.O\./si', $order->delivery['street_address'])) { 
                $this->enabled = false;
		$po_box_address = true;
      } else if ( preg_match('/P\.O/si', $order->delivery['street_address'])) { 
                $this->enabled = false;
		$po_box_address = true;
      } else if ( preg_match('/PO\./si', $order->delivery['street_address'])) { 
                $this->enabled = false;
		$po_box_address = true;
      }

That part works perfect and forces PO Box shipping address to have only USPS as a selection. Now I need to restrict a certain coupon code: "XXXXX" from being used for free shipping on PO Box shipping addresses only. ** A billing address can be a PO Box just not the shipping address.

I was thinking either ot_coupon.php file or coupon_restrict.php needs to be modified for this just not sure how to properly do it. Can anyone help on this?

12 Jan 2016, 12:27 AM
#2
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,962
Plugin Contributions:
8

Re: Restrict coupon code on PO Box shipping addresses

this will definitely be in the ot_coupon.php and more specifically in the collect_posts function.

based on your code something like this may work:

      $po_box_address = false;
      if ( preg_match('/PO BOX/si', $order->delivery['street_address'])) { 
        $po_box_address = true;
      } else if ( preg_match('/POBOX/si', $order->delivery['street_address'])) { 
        $po_box_address = true;
      } else if ( preg_match('/P\.O\./si', $order->delivery['street_address'])) { 
        $po_box_address = true;
      } else if ( preg_match('/P\.O/si', $order->delivery['street_address'])) { 
        $po_box_address = true;
      } else if ( preg_match('/PO\./si', $order->delivery['street_address'])) { 
        $po_box_address = true;
      }        
      if ($po_box_address) {
        $messageStack->add_session('redemptions', PO_BOX_WARNING, 'caution');
        $this->clear_posts();
        zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL',true, false));
      }

no guarantees.... also i would separate out the check PO box into a separate function and then call that function from both places. in my experience, PO BOX customers will do anything to get around the restrictions associated with their address. better to maintain the code in one place than in two.

good luck!

12 Jan 2016, 12:56 AM
#3
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
520
Plugin Contributions:
2

Re: Restrict coupon code on PO Box shipping addresses

it worked thank you!