Jump to content
hogava

change default gateway based on total amount

Recommended Posts

Hi, 

I need use other gateway when card total is more than 400$, with this hook othergateway shown when total is more than 400$ but that is not selected and if customer doesn't select othergateway then redirected to paypal. 

How can change default selected gateway from hook?

function cart_gateway_detection($vars)
{
    if ($vars['templatefile']=='viewcart'){
        $gateways = $vars['gateways'];
        $total = $vars['total']->toNumeric();
        if ($total <= 400){
            unset($gateways['paypal']);
        }
        else {
            unset($gateways['othergateway']);
        }
        return array("gateways" => $gateways);
    }
}
add_hook("ClientAreaPageCart"1"cart_gateway_detection");

Share this post


Link to post
Share on other sites
7 minutes ago, hogava said:

I need use other gateway when card total is more than 400$, with this hook othergateway shown when total is more than 400$ but that is not selected and if customer doesn't select othergateway then redirected to paypal. 

are you using a custom orderform template, e.g something other than standard_cart ?

because I would have thought if there are only two gateways, and the hook is removing one of them, then the cart should default the other gateway (effectively, it should be the only option shown to the user).

also, it's worth noting that the above hook isn't checking for currency - so if your site uses multiple currencies, then it would be triggered by $400, £400, €400 or ₹400 etc... in other words, it's just checking whether the total is less/equal to 400 in the current currency.

Share this post


Link to post
Share on other sites

Thanks for the explanation.

Yes I use standard_cart with customized template.

This JQuery code solved my problem:

jQuery("input:radio[name=paymentmethod]:visible")[0].checked=true;

 

Share this post


Link to post
Share on other sites

Now how can I apply this limitation about payment gateway in viewinvoice.php page too? 

Share this post


Link to post
Share on other sites
On 6/6/2020 at 5:38 PM, hogava said:

Now how can I apply this limitation about payment gateway in viewinvoice.php page too? 

@brian!  Please help me about this.

Share this post


Link to post
Share on other sites
3 hours ago, hogava said:

Please help me about this.

basically, it's still the same solution as the one I posted two years ago...

in that case, it's using limits based on the client's currency and then removing a specific gateway (e.g AsiaPay) from the dropdown - if you're only removing one gateway, then you can simply replace the content of that string... if it's multiple gateways, then you'll need multiple replaces.

thinking about it, there might be a need for an extra step with this solution - but if that's the case, you'll know as soon as you test it... that step will I suspect have been added to another hook posted elsewhere, but if you don't run into the issue, then you shouldn't need to worry about it.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated