Page 1 of 2

Disable payment option according to shipping

Posted: Tue Dec 20, 2011 3:21 am
by kaliyas
Hi guys how are you? I have two payment options (COD and Bank Transfer) and I have several shipping (A, B, C). I want to be a able to disable COD if customer selects "A" or "B" Shipping option.

I found this code and try to get it work on 1.5.13 without result.

Code: Select all

if(isset($this->session->data['shipping_method']['code']))
{
     if ($this->session->data['shipping_method']['code'] != 'cod.cod') 
     {
            $status = false;
     }
}
Can you give me hand?

Re: Disable payment option according to shipping

Posted: Tue Jan 03, 2012 9:19 am
by tschiff
an answer would be super nice...

Re: Disable payment option according to shipping

Posted: Tue Jan 03, 2012 10:57 pm
by Qphoria
well for starters:

if ($this->session->data['shipping_method']['code'] != 'cod.cod')

is not valid since cod is a payment method. Unless you have a custom cod shipping method.. that is unclear from the post.

But you can do this for each payment you want to alter.

1. EDIT: catalog/model/payment/somepay.php

2. FIND:

Code: Select all

if ($status) {
3. BEFORE, ADD:

Code: Select all

if (isset($this->session->data['shipping_method']['code']) && $this->session->data['shipping_method']['code'] == 'flat.flat') {
    $status = false;
}

Re: Disable payment option according to shipping

Posted: Fri Jan 06, 2012 11:06 pm
by ronwong
Dont seem to work, I just tried it on COD on latest 1.5.1.3

I want to disable COD if item ship by post (weight) because I cannot mail the thing and go and collect cash.

I included the code in the cod.php file:

Code: Select all

if (isset($this->session->data['shipping_method']['code']) && $this->session->data['shipping_method']['code'] == 'weight.weight') {
    $status = false;
}

Re: Disable payment option according to shipping

Posted: Fri Jan 06, 2012 11:40 pm
by Qphoria
Code isn't weight.weight for weight as it has multiple rates
try just "weight" or maybe

Code: Select all

if (isset($this->session->data['shipping_method']['code']) && strpos($this->session->data['shipping_method']['code'], 'weight') !== false) {
    $status = false;
}

Re: Disable payment option according to shipping

Posted: Sat Jan 07, 2012 1:23 am
by Johnathan
I've now released a Restrict Payment Methods extension that allows you to limit the availability of payment methods based on the shipping method selected.

It also can restrict based on customer group, currency, cart quantity/sub-total/volume/weight/date, category, manufacturer, or product.

Re: Disable payment option according to shipping

Posted: Sat Jan 07, 2012 9:15 am
by ronwong
Jonathan, I appreciate your offer, I have seen the paid addons, they must be good but I had spent a bit too much for the time for open source platform.

Qphoria, I took your code and it works, I am no programmer so just see and derive, and there is an issue the way the page loads, for example, when the "weight" method is choosen, next, COD is hidden, perfect, but then it is "locked", so if the customer decide to change his mind and scrolls back to change to self collect now, it wont reappear, or if they decide original for deivery, COD available, the go back and change to weight shipping, and COD is still there, they have to go through the whole "session" of checkout without changing their mind for it to work.

Re: Disable payment option according to shipping

Posted: Thu Jan 12, 2012 7:07 pm
by jim_vam
ronwong wrote:Jonathan, I appreciate your offer, I have seen the paid addons, they must be good but I had spent a bit too much for the time for open source platform.

Qphoria, I took your code and it works, I am no programmer so just see and derive, and there is an issue the way the page loads, for example, when the "weight" method is choosen, next, COD is hidden, perfect, but then it is "locked", so if the customer decide to change his mind and scrolls back to change to self collect now, it wont reappear, or if they decide original for deivery, COD available, the go back and change to weight shipping, and COD is still there, they have to go through the whole "session" of checkout without changing their mind for it to work.
+1 for me also looking for the same thing. That is to restrict payment option depending on shipping option.

Re: Disable payment option according to shipping

Posted: Sat Jan 14, 2012 7:49 am
by straightlight
A simple line of editing from the checkout payment core with VQMod should suffice to apply these type of modifications. Also, building a contribution for such subject could be endless while this if statement could also grow larger at anytime from the XML.

Re: Disable payment option according to shipping

Posted: Wed Jan 18, 2012 2:06 am
by pdm
ronwong wrote:Qphoria, I took your code and it works, I am no programmer so just see and derive, and there is an issue the way the page loads, for example, when the "weight" method is choosen, next, COD is hidden, perfect, but then it is "locked", so if the customer decide to change his mind and scrolls back to change to self collect now, it wont reappear, or if they decide original for deivery, COD available, the go back and change to weight shipping, and COD is still there, they have to go through the whole "session" of checkout without changing their mind for it to work.
Hi quys,
This method works, but you have to do a small change, try this:

1. Edit catalog/controller/checkout/shipping.php

FIND:

Code: Select all

if (!$json) {
				$shipping = explode('.', $this->request->post['shipping_method']);
AND REPLACE:

Code: Select all

if (!$json) {		
				unset($this->session->data['payment_methods']);
				unset($this->session->data['payment_method']); 
				$shipping = explode('.', $this->request->post['shipping_method']);
For me works, even if the customer changes their mind and change the delivery method.

Re: Disable payment option according to shipping

Posted: Wed Mar 07, 2012 1:52 am
by eline
Hello
I have problem with 1.5.1.3 payments, to enable COD when weight_5 is selected. I dont supply goods outside country with COD, so I have to find a method to disable COD for all other zones - just not zone weight_5. Shipping method is only one - depend on weight. Any clue?

Re: Disable payment option according to shipping

Posted: Thu Jul 12, 2012 7:16 pm
by zoltrix
The code(Qphoria) worked for me on 1.5.3.1:
before
if ($status) {
on /catalog/model/payment/cod.php

Code: Select all

if (isset($this->session->data['shipping_method']['code']) && $this->session->data['shipping_method']['code'] == 'free.free') {
    		$status = false;
		}
My example:
Over 50 Euros free shipping selected hide on step 5 the module COD and only showing PAYPAL and bank transfer.

Re: Disable payment option according to shipping

Posted: Tue Jul 17, 2012 3:35 pm
by allen551210
Hi guys how are you?

How to change the comment to required field ?

If comments is empty, to alert a warring.

Re: Disable payment option according to shipping

Posted: Wed Jul 18, 2012 2:37 am
by straightlight
In catalog/controller/checkout/shipping_method.php file,

find:

Code: Select all

if (!isset($shipping[0]) || !isset($shipping[1]) || !isset($this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]])) {			
					$json['error']['warning'] = $this->language->get('error_shipping');
				}
add after:

Code: Select all

if (empty($this->request->post['comment'])) {
    $json['error']['warning'] = $this->language->get('error_comment');
}
In catalog/language/english/checkout/checkout.php file,

find:

Code: Select all

$_['error_shipping']
add below:

Code: Select all

$_['error_comment'] = 'Please fill out the comment box.';
This should do it.

Re: Disable payment option according to shipping

Posted: Tue Aug 14, 2012 6:23 pm
by ShopOholic
pdm wrote:
ronwong wrote:Qphoria, I took your code and it works, I am no programmer so just see and derive, and there is an issue the way the page loads, for example, when the "weight" method is choosen, next, COD is hidden, perfect, but then it is "locked", so if the customer decide to change his mind and scrolls back to change to self collect now, it wont reappear, or if they decide original for deivery, COD available, the go back and change to weight shipping, and COD is still there, they have to go through the whole "session" of checkout without changing their mind for it to work.
Hi quys,
This method works, but you have to do a small change, try this:

1. Edit catalog/controller/checkout/shipping.php

FIND:

Code: Select all

if (!$json) {
				$shipping = explode('.', $this->request->post['shipping_method']);
AND REPLACE:

Code: Select all

if (!$json) {		
				unset($this->session->data['payment_methods']);
				unset($this->session->data['payment_method']); 
				$shipping = explode('.', $this->request->post['shipping_method']);
For me works, even if the customer changes their mind and change the delivery method.

I've tried this, but it doesn't seem to work. It wont change back if the customer changes their mind. Anyone have a solution?

Re: Disable payment option according to shipping

Posted: Thu Oct 11, 2012 11:10 pm
by SelfMan
Works for me very nicely. Both modification have to be applied as described above to get it working properly. (cod.php and shipping.php)

Re: Disable payment option according to shipping

Posted: Fri Oct 12, 2012 6:54 pm
by bluebeard
Qphoria wrote:Code isn't weight.weight for weight as it has multiple rates
try just "weight" or maybe

Code: Select all

if (isset($this->session->data['shipping_method']['code']) && strpos($this->session->data['shipping_method']['code'], 'weight') !== false) {
    $status = false;
}
This worked for me. I wanted COD to be disabled if weight-based shipping had been selected ;)

Re: Disable payment option according to shipping

Posted: Sat Oct 13, 2012 12:26 am
by tolinho
Qphoria wrote:1. EDIT: catalog/model/payment/somepay.php

2. FIND:

Code: Select all

if ($status) {
3. BEFORE, ADD:

Code: Select all

if (isset($this->session->data['shipping_method']['code']) && $this->session->data['shipping_method']['code'] == 'flat.flat') {
    $status = false;
}
Thanks :)
Works perfectly in 1.5.4.1.

Re: Disable payment option according to shipping

Posted: Sun Oct 14, 2012 8:38 pm
by bluebeard
bluebeard wrote:
Qphoria wrote:Code isn't weight.weight for weight as it has multiple rates
try just "weight" or maybe

Code: Select all

if (isset($this->session->data['shipping_method']['code']) && strpos($this->session->data['shipping_method']['code'], 'weight') !== false) {
    $status = false;
}
This worked for me. I wanted COD to be disabled if weight-based shipping had been selected ;)
Hi again! While the above worked like a charm, i have another question - i want Paypal standard to be disabled when Pickup From Store is selected, leaving COD as the only payment option.

So applying in the same logic that Qphoria taught us here, in my pickup.php i inserted the following above

Code: Select all

$status = false;

Code: Select all

		if (isset($this->session->data['payment_method']['code']) && strpos($this->session->data['payment_method']['code'], 'pp_standard') !== false) {
And uh.. unsurprisingly it doesn't work, since i am not much of an OC expert :clown:

Any help would be much appreciated. Thank you!

Re: Disable payment option according to shipping

Posted: Sun Aug 11, 2013 1:10 am
by rdvapors
Would it be possible to restrict payment and shipping on coupon code?

Example
Coupon Code = FREE
Conditions of Coupon Code:
Fixed amount = $x.xx

customer enters coupon code,
payment and shipping are disabled

also
if customer adds another item payment payment and shipping becomes active and coupon code fixed amount remains active.

also
if customer adds enough items to satisfy free shipping amount, coupon code remains active at fixed amount and shipping is disabled.

also
only this coupon code will work.

Visual example

Cart amount:
$5.98
Coupon Code FREE entered,
Coupon Code FREE Applied -$5.98
Cart total = $0.00
Shipping = Free
checkout success.

CONDITION 2
Cart amount:
$15.98
Coupon Code Free entered,
Coupon Code FREE Applied -$5.98
Cart total =$10.00
Shipping = "Whatever shipping"
Shipping selected,
Payment info entered,
checkout success.

CONDITION 3
Cart amount:
$50.00
Coupon Code FREE entered,
Coupon Code FREE applied -$5.98
Cart total =$44.02 "Free Shipping Triggered"
Payment info entered,
checkout success.