BeaverProj
BeaverProj

Reputation: 2215

How to Set the Credit Card payment method as default (selected) when there is more than one payment method in Magento

Is there a way to make the Credit Card payment method always selected and open initially when there are more than one payment method? This is in the Checkout process.

Upvotes: 2

Views: 8357

Answers (2)

BeaverProj
BeaverProj

Reputation: 2215

Here's what I ended up doing.

  • Copy the \website\app\design\frontend\base\default\template\checkout\onepage\payment\methods.phtml file to the equivalent directory in my theme.

  • Add a new loop counter variable, $i, at the top after the first comment:

    $i = 1;

  • Inside the <?php if( sizeof($this->getMethods()) > 1 ): ?> first if conditional check, add the following condition (basically, it checks if this the first payment method and sets it to checked)

    <?php if( $i == 1 ): ?>
        <input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" checked="checked" title="<?php echo $this->htmlEscape($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>')" class="radio" />
    <?php else: ?>
        <input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->htmlEscape($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>')"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio" />
    <?php endif; ?>
    

The else condition is the same as before.

  • Just before the <?php endforeach; ?> I added this line (with <?php around it):

    $i = $i + 1;

EDIT:

Actually, the only reliable cross-browser way to keep it open was to copy the file here: \app\design\frontend\base\default\template\payment\form\ccsave.phtml to my theme and then remove the style="display: none;" from the first .

That fixed it so the form was always open and the above code made sure it was selected by default.

Upvotes: 1

Anton S
Anton S

Reputation: 12750

you can try this on earlier steps with observer

try {
    $quote->getPayment()->setMethod('method_code')->getMethodInstance();
} catch ( Exception $e ) {
    Mage::logException($e);
}

but be aware that this payment method has to be active and ready to use before you can set this also and you must check if there is no payment method selected before so you won't change the user selection or force the same payment method for each order and you may have to change some frontend code to open up payment method form.

Upvotes: 0

Related Questions