Freddykhoury Posted December 21, 2022 Share Posted December 21, 2022 Hello, I need to restrict some payment methods from the website. When I select only "Lebanon" it allow any country to see this specific payment, if i select any other country ex: sweeden only, only sweeden can see the payment methods ex: I unchecked all countires from COD and slected Lebanon, the result is that all countries can see COD. if I select any country it is only seen by this country any idea? thank you Link to comment Share on other sites More sharing options...
ps8modules Posted December 21, 2022 Share Posted December 21, 2022 Hi, there is a need to change the behavior for the default country. Link to comment Share on other sites More sharing options...
Freddykhoury Posted December 21, 2022 Author Share Posted December 21, 2022 My defaut country was the US and I changed the default language to english and still from my VPN open sweden i can see the stripe payment or COD and I just selected Lebanon any other solution? Link to comment Share on other sites More sharing options...
ps8modules Posted December 21, 2022 Share Posted December 21, 2022 Unfortunately, I do not have the COD module available. I can't write you a solution like this. Did you contact the module developer? Do you use a standard checkout or a one page checkout module? Thank you Link to comment Share on other sites More sharing options...
Knowband Plugins Posted December 21, 2022 Share Posted December 21, 2022 For restricting the country from the credit card or COD payment, kindly try by adding the below code in the main file of the credit card/COD payment module, Function : hookPaymentOptions($params) =>First Fetch the customer country from the saved address using the below code $address = new Address(context::getContext()->customer->id_address_delivery); $selected_add_country_id = $address ->id_country; =>Then check whether the current country is US or not, if not then use the below code return; The above code will check whether the customer country is US or not, if not then that payment method is not available on the front for that customer, otherwise the payment method is available. Link to comment Share on other sites More sharing options...
Freddykhoury Posted December 21, 2022 Author Share Posted December 21, 2022 I am not sure I did the right update. I am not a professional programer. but it did not work when I tried to add it in the COD . the settings is set to be displayed only in Lebanon and it shows from any country the problem is only when I select Lebanon can you tell me where should it be added in the ps_cashondelivery.php Thanks Link to comment Share on other sites More sharing options...
Knowband Plugins Posted December 22, 2022 Share Posted December 22, 2022 Kindly use the below code for reference : public function hookPaymentOptions($params) { if (!$this->active) { return; } $address = new Address(context::getContext()->cart->id_address_delivery); $selected_add_country_id = $address ->id_country; if($selected_add_country_id != "Your-Country-Code"){ return; } if (!$this->checkCurrency($params['cart'])) { return; } Link to comment Share on other sites More sharing options...
Freddykhoury Posted December 22, 2022 Author Share Posted December 22, 2022 as I said I am not a programer nd dont know where to add this funciton There is already a function for hook payment where should it be added? public function hookPaymentOptions(array $params) { if (empty($params['cart'])) { return []; } /** @var Cart $cart */ $cart = $params['cart']; if ($cart->isVirtualCart()) { return []; } $cashOnDeliveryOption = new PaymentOption(); $cashOnDeliveryOption->setModuleName($this->name); $cashOnDeliveryOption->setCallToActionText($this->trans('Pay by Cash on Delivery', [], 'Modules.Cashondelivery.Shop')); $cashOnDeliveryOption->setAction($this->context->link->getModuleLink($this->name, 'validation', [], true)); $cashOnDeliveryOption->setAdditionalInformation($this->fetch('module:ps_cashondelivery/views/templates/hook/paymentOptions-additionalInformation.tpl')); return [$cashOnDeliveryOption]; } thank you Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now