Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prestashop: payment method depending on postcode

I'm new to prestashop and I need to know if there is a way (via code) by which I can restrict the number of payment gateways available according to customer postcode. For example, let's say that anyone who buys from New York can only pay via PayPal but the rest cities in US can use any payment gateway.

I tried this, but it disables modules for everyone not for a particular client:

if (strcmp($postcode, "12345")) // postcode I want to restrict
{
   // disabling other payment modules
   $modules = PaymentModuleCore::getInstalledPaymentModules();
   foreach ($modules as $module)
   {
      // fetch all installed module names
      $name = $module['name'];
      if (strcmp($name, "Paypal") != 0)
         Module::getInstanceByName($name)->disable();
   }
}
like image 556
Leonardo Lanchas Avatar asked Feb 15 '26 08:02

Leonardo Lanchas


1 Answers

As nobody answers, I've fixed this problem with Jquery, deleting the other options in the module .tpl

-- EDIT --

At the end of the template, I added this line of JS:

<script type="text/javascript"> 
    $(".payment_module").not(".mypaymentmodule").remove();
</script>
like image 194
Leonardo Lanchas Avatar answered Feb 19 '26 22:02

Leonardo Lanchas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!