To hide some payment methods based on shipping method you don't need to observe things at all:
Every methods(in one page check out) post the methods which are chosen to the next level. So you can get the shipping method which are chosen, in payment method level. Just print the post things in
app/design/frontend/base/default/template/checkout/onepage/payment/methods.phtml
in this add below one,
<?php print_r($_POST); ?>
So now you can get the shipping methods which are chosen previous step. And note it, so now, you can add just simple logic (if else) condition in same file for hiding payment.
For example here I want hide check / money order
payment method, if shipping method is flat
. Here the payment method code is checkmo
. you can get payment method code by simply printing that variable like echo $_code = $_method->getCode();
in same file. so here just add simple if else ,
<?php
$methods = $this->getMethods();
$oneMethod = count($methods) <= 1;
?>
<?php if (empty($methods)): ?>
<dt>
<?php echo $this->__('No Payment Methods') ?>
</dt>
<?php else:
foreach ($methods as $_method):
echo $_code = $_method->getCode();
if($_POST['shipping_method'] == 'flatrate_flatrate') {
if($_code == 'checkmo') {
continue;
}
}
?>
Here,
if($_POST['shipping_method'] == 'flatrate_flatrate') {
if($_code == 'checkmo') {
continue;
}
}
checks the shipping method and skip the payment method which we don't want to display. That's it. Please comment here if you have any doubt.
Note:
shipping_method => flatrate_flatrate
payment_method => checkmo
Best Answer
There are a few ways to do this. One solution is to create a module that gives you a multi-select box in the admin area to chose which methods will be active. That solution is provided here, but is likely more involved than needed for your situation.
The method that I think will work better for you is provided here. This goes over how to write a simple module that will hide methods based on conditions you define. The example is set up to hide the
flatrate
shipping method from customers who are not logged in. To adjust for your situation, lets assume you create a shipping method calledstaffOnly
. Then the_checkCarrierAvailability
method for you would look like:Now when the code iterates through to grab all the available shipping methods, it will skip the one called
staffOnly
, and it will never be rendered as an option at frontend checkout.