hogava Posted June 6, 2020 Share Posted June 6, 2020 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"); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 6, 2020 Share Posted June 6, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
hogava Posted June 6, 2020 Author Share Posted June 6, 2020 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; 0 Quote Link to comment Share on other sites More sharing options...
hogava Posted June 6, 2020 Author Share Posted June 6, 2020 Now how can I apply this limitation about payment gateway in viewinvoice.php page too? 0 Quote Link to comment Share on other sites More sharing options...
hogava Posted June 8, 2020 Author Share Posted June 8, 2020 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. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 8, 2020 Share Posted June 8, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.