Jump to content

Select Payment Method by Default


eManager

Recommended Posts

We use the one-page checkout with three different payment modules.  We would like to have one of them set as the default when the page loads so the credit card, exp, and [spam-filter] filed are displayed without needing to click that option.  Any advice?

Link to comment
Share on other sites

  • 2 weeks later...
  • 8 months later...

EDIT: My Mistake, default carrier,not default payment method...

 

 

 

Hi Sabio,

 

In PS 1.6, go to Shipping->Preferences, scroll down and there you have a field default carrier

post-455771-0-12620400-1413130964_thumb.png

 

in PS 1.5, go to Shipping->Shipping, scroll down and there you have a field default carrier.

post-455771-0-33518100-1413130979_thumb.png

 

 

Hope this helps,

pascal

Edited by PascalVG
My mistake: Default carrier, not default payment method... (see edit history)
Link to comment
Share on other sites

Also looking at this, in most platform this is an option, indeed a very important one, as the transaction fees may very.

What payment module are you using?  Does it require that you click the payment method first, and then the credit card form is presented on a separate page?

Link to comment
Share on other sites

  • 1 year later...
  • 11 months later...
  • 2 weeks later...
  • 2 weeks later...

The correct way is to send select_payment_option to order controller.

 

The easy way:

 

In templates/checkout/_partials/steps/checkout-step.tpl

 

add

{if "payment-option-3" == $option.id} checked {/if}

 

instead of 

{if $selected_payment_option == $option.id} checked {/if}

Link to comment
Share on other sites

  • 6 months later...
On 21/4/2017 at 11:48 AM, serafimsorovsky said:

The correct way is to send select_payment_option to order controller.

 

The easy way:

 

In templates/checkout/_partials/steps/checkout-step.tpl

 

add

{if "payment-option-3" == $option.id} checked {/if}

 

instead of 

{if $selected_payment_option == $option.id} checked {/if}

 

This work but it dosen't show the payment decription "id="payment-option-1-additional-information""

Is there a way to show this also by default ?

Link to comment
Share on other sites

  • 1 month later...

My solution for version 1.7:

in templates/checkout/_partials/steps/payment.tpl
change:

              <input
                class="ps-shown-by-js {if $option.binary} binary {/if}"
                id="{$option.id}"
                data-module-name="{$option.module_name}"
                name="payment-option"
                type="radio"
                required
                {if $selected_payment_option == $option.id || $is_free} checked {/if}
              >


to:

              <input
                class="ps-shown-by-js {if $option.binary} binary {/if}"
                id="{$option.id}"
                data-module-name="{$option.module_name}"
                name="payment-option"
                type="radio"
                required
                checked
              >

             
change:

        {if $option.additionalInformation}
          <div
            id="{$option.id}-additional-information"
            class="js-additional-information definition-list additional-information{if $option.id != $selected_payment_option} ps-hidden {/if}"
          >
            {$option.additionalInformation nofilter}
          </div>
        {/if}


to:

    <div>
		{$option.additionalInformation nofilter}
	</div>

 

Link to comment
Share on other sites

  • 3 weeks later...
  • 4 weeks later...

The above solution sets the radio button for the payment option to "selcted" regardless of the number of available payment options. I was not very keen on forcing this, so I used an if statement to check wether there is only one payment option available:

 

Replace line 21:

                {elseif $selected_payment_option == $option.id} checked

with:

 

                {if $module_options|@count eq 1} checked
                {elseif $selected_payment_option == $option.id} checked
                {/if}

 

Link to comment
Share on other sites

  • 7 months later...

Not having any luck with either of those solutions - netfuchs' solution doesn't appear to work on my shop, and I can't even find the code that Solaris is referring to (not sure what file it's in).

 

Anyone else?  This seems like an obvious option to be available in the standard backend?

Link to comment
Share on other sites

  • 2 weeks later...

Neither option works for me either.  On almost all of my stores I only offer one payment option, and it seems a bit confusing and redundant to have to choose the only option available.  I'm not a developer, but it seems this should be a simple fix, or as to djachela's point, a standard option.  Anyone have a solution for 1.7.4.2?

Link to comment
Share on other sites

8 hours ago, ableier said:

Neither option works for me either.  On almost all of my stores I only offer one payment option, and it seems a bit confusing and redundant to have to choose the only option available.  I'm not a developer, but it seems this should be a simple fix, or as to djachela's point, a standard option.  Anyone have a solution for 1.7.4.2?

Solutions have already been provided that work with PS v1.7.4.2

Perhaps you are using a custom theme or perhaps the payment module you are using is somehow interfering.  Also possible that you are not applying the solution correctly.

Link to comment
Share on other sites

2 minutes ago, bellini13 said:

Solutions have already been provided that work with PS v1.7.4.2

 

Could you link to them?  Nothing I've seen works for me.

 

Quote

Perhaps you are using a custom theme or perhaps the payment module you are using is somehow interfering.  Also possible that you are not applying the solution correctly.

I'm using the standard theme.  Payment module could well be interfering, but if that's possible then I'd suggest that this is something which should be a feature that can't be interfered with?  Seems bizarre if a module can trump settings from elsewhere.

Totally possible I'm not applying it correctly, but the two I've looked at in this thread I've covered, and I'm near certain I didn't screw up applying netfuchs' one (I've tried it twice, from scratch, just in case).

Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...
On 12/23/2018 at 1:52 PM, arasheb said:

Just add this code in some where in your javascript code

if($('label[for=payment-option-1]').length!=0)
        $('label[for=payment-option-1]').trigger('click');

You can change 1 to any payment you want choose by default

for me right now showing all options. but not particularly option one.

Link to comment
Share on other sites

I found solution! 

case: if you want selected default payment option and another option dont displayed additional info.

payment.tpl

<span class="custom-radio float-xs-left">
    <input class="ps-shown-by-js {if $option.binary} binary {/if}"
                 id="{$option.id}"
                 data-module-name="{$option.module_name}"
                 name="payment-option"
                 type="radio"
                required
               {if 'payment-option-1' == $option.id || $is_free} checked {/if}  <--update this line
     >
    <span></span>
</span>

and refactoring this line: (add extra if statement)

extra TIP: if you want to move payment row ordet methods use paymentOptions hook in display->position and select unpositional hooks :)

{if $option.additionalInformation && $option.id == 'payment-option-1' }
    <div>
         {$option.additionalInformation nofilter}
     </div>
{else}
<div id="{$option.id}-additional-information"
         class="js-additional-information definition-list additional-information{if $option.id != $selected_payment_option} ps-hidden {/if}"
>
{$option.additionalInformation nofilter}
</div>
{/if}
Edited by Darius1990 (see edit history)
Link to comment
Share on other sites

  • 4 months later...
On 12/12/2017 at 2:18 PM, netfuchs said:

My solution for version 1.7:

in templates/checkout/_partials/steps/payment.tpl
change:


              <input
                class="ps-shown-by-js {if $option.binary} binary {/if}"
                id="{$option.id}"
                data-module-name="{$option.module_name}"
                name="payment-option"
                type="radio"
                required
                {if $selected_payment_option == $option.id || $is_free} checked {/if}
              >


to:


              <input
                class="ps-shown-by-js {if $option.binary} binary {/if}"
                id="{$option.id}"
                data-module-name="{$option.module_name}"
                name="payment-option"
                type="radio"
                required
                checked
              >

             
change:


        {if $option.additionalInformation}
          <div
            id="{$option.id}-additional-information"
            class="js-additional-information definition-list additional-information{if $option.id != $selected_payment_option} ps-hidden {/if}"
          >
            {$option.additionalInformation nofilter}
          </div>
        {/if}


to:


    <div>
		{$option.additionalInformation nofilter}
	</div>

 

I do this steps and also remove that article section that is for prevention user from finaliazing order without selecting payment method. and every thing is okey there. but my card ajax opration does not work any more and I am getting this error:

 

[PrestaShopDatabaseException]

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DigiShi Carrier');","1399":"MBG.addCheckoutOption(2,'DigiShi Carrier');","1400":' at line 1

how can I resolve this error?  

Link to comment
Share on other sites

  • 1 year later...
On 1/24/2018 at 1:14 PM, Solaris said:

The above solution sets the radio button for the payment option to "selcted" regardless of the number of available payment options. I was not very keen on forcing this, so I used an if statement to check wether there is only one payment option available:

 

Replace line 21:


                {elseif $selected_payment_option == $option.id} checked

with:

 


                {if $module_options|@count eq 1} checked
                {elseif $selected_payment_option == $option.id} checked
                {/if}

 

This worked - selected option but then on the bottom of the cart button is inactive due to you need to select option. So need to click again to get js reloaded

Link to comment
Share on other sites

  • 5 weeks later...

See https://github.com/PrestaShop/PrestaShop/pull/21654/files/58878162576eb30dc4a72e8075359a1bb42fd7bd

Presta Developers already fixed this for Milestone 1.7.8

replace

{if $selected_payment_option == $option.id || $is_free} checked {/if}

with

{if ($selected_payment_option == $option.id || $is_free) || ($payment_options|@count === 1 && $module_options|@count === 1)} checked {/if}

in /themes/YOURTHEME(_CHILD)/templates/checkout/_partials/steps/payment.tpl

that´s it 😉

---

But they missed the additionalInformation to open too. 😒

 

So you might use this code instead:

{if ($selected_payment_option == $option.id || (isset($is_free) && $is_free) ) || ($payment_options|@count === 1 && $module_options|@count === 1)} checked {$selected_payment_option = $option.id} {/if}

and add this else condition in the class :

{if $option.additionalInformation}
  <div
  	id="{$option.id}-additional-information"
    class="js-additional-information definition-list additional-information {if $option.id != $selected_payment_option} ps-hidden {else} ps-shown-by-js {/if}"
  >
  	{$option.additionalInformation nofilter}
  </div>
{/if}

 

Works fine for me in PS 1.7.7.2 😊

cheers

 

Edited by hamsta (see edit history)
Link to comment
Share on other sites

  • 1 year later...

Hello, I hope y'all doing good. 

I have tried some of the provided solutions and was able to actually make my first payment method the default payment method.

However, I can't see the other payment method, the radio buttons aren't showing at all. 

So basically visitors can just click submit and they will be taken to Payment method No1, I would like both the methods to be available in radio buttons... which seems to be "hidden" using JS for some reason.

I'm running Prestashop 1.7.4.2 

Link to comment
Share on other sites

On 1/29/2019 at 10:37 AM, Darius1990 said:

I found solution! 

case: if you want selected default payment option and another option dont displayed additional info.

payment.tpl

<span class="custom-radio float-xs-left">
    <input class="ps-shown-by-js {if $option.binary} binary {/if}"
                 id="{$option.id}"
                 data-module-name="{$option.module_name}"
                 name="payment-option"
                 type="radio"
                required
               {if 'payment-option-1' == $option.id || $is_free} checked {/if}  <--update this line
     >
    <span></span>
</span>

and refactoring this line: (add extra if statement)

extra TIP: if you want to move payment row ordet methods use paymentOptions hook in display->position and select unpositional hooks :)

{if $option.additionalInformation && $option.id == 'payment-option-1' }
    <div>
         {$option.additionalInformation nofilter}
     </div>
{else}
<div id="{$option.id}-additional-information"
         class="js-additional-information definition-list additional-information{if $option.id != $selected_payment_option} ps-hidden {/if}"
>
{$option.additionalInformation nofilter}
</div>
{/if}

This is what I have used, step one, in order to make Payment option 1 the default payment method, as it was gone from checkout once I have installed a new payment module in the backoffice.

Link to comment
Share on other sites

  • 10 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...