1

we are using 5 Payment methods with payment methods codes are "code1, code2 , code3, code4 and code5".

for site purpose we are using code1 , code2, code3 payment methods.

we have mobile app for our site, for that purpose,

we are using code4 , code5 payment methods.

So code4 and code5 payment methods should not display in site. so i removed those payment methods name. but code4 and code5 payment methods RADIO BUTTONS are still displaying in the site.

enter image description here

in methods.phtml i used this script to remove those radio buttons

foreach ($methods as $_method):
$_code = $_method->getCode();
if($_code == 'innobyte_payu_lite_cc' or $_code == 'cashondelivery'{continue;} //this line
?>

but those Radio buttons are not hiding. If we disabled the payment method code "code3" than those radio buttons will hide. but we want the payment method code3 in our site.

How to hide those radio buttons with payment method code3 enabled in site.

4 Answers 4

1

Try this:

app/design/frontend/your_packge/your_theme/template/checkout/onepage/payment/methods.phtml

Add bellow code above file after code :foreach ($methods as $_method): $_code = $_method->getCode(); ?>

Add code in file:

<?php if(in_array($_code,array('cashondelivery','innobyte_payu_lite_cc'))):?>
    <?php continue;?>
<?php endif;?>
5
  • still those payment methods radio buttons are displaying : pastebin.com/Q2FEkpK9 Commented Dec 23, 2015 at 7:50
  • Pls add : <?php if(in_array($_code ,array('innobyte_payu_lite_cc','cashondelivery'))):?> <?php continue;?> <?php endif;?>
    – Abdul
    Commented Dec 23, 2015 at 7:53
  • i added, please check line number 66 here : pastebin.com/Q2FEkpK9 Commented Dec 23, 2015 at 7:54
  • in your file : $_code = $_method->getCode(); var name is "$_code"
    – Abdul
    Commented Dec 23, 2015 at 7:55
  • then must be add $_code in if condition like : <?php if(in_array($_code,array('code4','code5'))):?> <?php continue;?> <?php endif;?>
    – Abdul
    Commented Dec 23, 2015 at 7:56
1

As for I got, you trying to hide some payment methods based on shipping method. For this you don't need to observe things at all. Simply you can do this, just follow me,

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
 paymet_method   => checkmo

please try this update

if($_code == 'code1') {
    continue;
}

if($_code == 'code2') {
    continue;
}

I hope this will help you.

15
  • Great answer. i am not worrying about shipping method . all i need is i need to hide radio button of 2 payment methods. asssume payment method codes are : "code1 and code2" . please update the answer. Commented Dec 23, 2015 at 6:23
  • please try update...if it is relevant to you. Commented Dec 23, 2015 at 6:34
  • now both payment methds radio button are displaying Commented Dec 23, 2015 at 6:47
  • do print_($_code) exit; and debug with it because the code you defined is may be differ in actual. Commented Dec 23, 2015 at 6:48
  • "cashondelivery" is other payment method code Commented Dec 23, 2015 at 6:49
1

simply use this or condition work for you.

foreach ($methods as $_method):
            $_code = $_method->getCode();
            if($_code == 'cashondelivery' or $_code == 'YOUR_CODE2'){continue;}
            ?>
11
  • now both payment methods radio button are displaying. Commented Dec 23, 2015 at 6:47
  • you don't want to show? Commented Dec 23, 2015 at 6:52
  • i dont want to show both radio buttons Commented Dec 23, 2015 at 6:52
  • update the answer Commented Dec 23, 2015 at 6:55
  • got the real problem. we are using one payment method [code = "code3"], when we enable that payment method , its not working for both. when i disable that payemtn method your solution is working. Commented Dec 23, 2015 at 7:02
1

You can try this way.

foreach ($methods as $_method):
    $_code = $_method->getCode();
    if($_code!="code1" || $_code!="code2"){//display the methods.
        here unwanted methods are not show.
}

try this way. Assign your requested methods to an array.

foreach ($methods as $_method):
$_code = $_method->getCode();
 $requestedmethod = array("method1","method2");//You have you methods codes
 if(in_array($_code,$requestedmethod)){
  //This will omit the unwanted method and Show only the methods you want
 } 

UPDATE : you can use this code .Just Try this.i Check your page and found three methods you want to show.so i added those 3 methods to array and check while iterating the foreach.

foreach ($methods as $_method):
    $_code = $_method->getCode();
    $requested_paymont_methods = array("mpcashondelivery","hdfc_standard","payucheckout_shared");
 <?php if(!$oneMethod): ?>
if(in_array($_code,$requested_paymont_methods)){?>
  //This will omit the unwanted method and Show only the methods you want
<input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->escapeHtml($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>')"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio" />
 <?php } ?>
<?php else: ?>
8
  • now both payment methds radio button are displaying Commented Dec 23, 2015 at 6:47
  • use the in_array method
    – Mujahidh
    Commented Dec 23, 2015 at 6:59
  • got the real problem. we are using one payment method [code = "code3"], when we enable that payment method , its not working for both. when i disable that payemtn method your solution is working. Commented Dec 23, 2015 at 7:02
  • So you find a solution right :).
    – Mujahidh
    Commented Dec 23, 2015 at 7:04
  • no this is the problem. i can not displae that payment method Commented Dec 23, 2015 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.