Craft Posted December 17, 2022 Share Posted December 17, 2022 Hello, I'm offering a Free Trial period for my web hosting service, so when the customer goes to the Checkout page, he sees the Total price is $0.00 and he should select the payment method (Credit Card) or (PayPal), so he thoughts that we gonna charge him or trick him, so he refuses to continue! How can I hide the Payment section when the Total price is $0.00? 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 17, 2022 Share Posted December 17, 2022 I have made this hook for you now try it and tell me if works with you 0 Quote Link to comment Share on other sites More sharing options...
Craft Posted December 17, 2022 Author Share Posted December 17, 2022 (edited) 1 hour ago, AladdinJ said: I have made this hook for you now try it and tell me if works with you First of all, I would like to thank you for your time and effort 🙂 The payment options (Credit Card / PayPal) became hidden, but the credit card fields still exist. Can you force selecting the payment method (PayPal) before hiding the payment section? I think this issue will be solved if you did that. Edited December 17, 2022 by Craft 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 17, 2022 Share Posted December 17, 2022 you are right , I have updated it now I made it wait 1 second before hide the elements , that fixed the problem 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 17, 2022 Share Posted December 17, 2022 also I have made a way as You mentioned selecting PayPal then Hide the Payment Gateways Only add_hook('ClientAreaPageCart', 1, function($vars) { if ($vars['rawtotal'] == 0.00) { add_hook('ClientAreaFooterOutput', 1, function($vars) { $v = "input[value='paypal']"; $return = ' <script> document.querySelector("'.$v.'").checked = true; const PGC = document.getElementById("paymentGatewaysContainer"); PGC.style.display = "none"; '; return $return; }); } }); you can try any one you like I left the both ways in the file 0 Quote Link to comment Share on other sites More sharing options...
Craft Posted December 17, 2022 Author Share Posted December 17, 2022 43 minutes ago, AladdinJ said: you are right , I have updated it now I made it wait 1 second before hide the elements , that fixed the problem This version hides the payment methods but the issue that it's still reading the credit card fields and still asking us to fill up the mandatory fields 0 Quote Link to comment Share on other sites More sharing options...
Craft Posted December 17, 2022 Author Share Posted December 17, 2022 11 minutes ago, AladdinJ said: also I have made a way as You mentioned selecting PayPal then Hide the Payment Gateways Only add_hook('ClientAreaPageCart', 1, function($vars) { if ($vars['rawtotal'] == 0.00) { add_hook('ClientAreaFooterOutput', 1, function($vars) { $v = "input[value='paypal']"; $return = ' <script> document.querySelector("'.$v.'").checked = true; const PGC = document.getElementById("paymentGatewaysContainer"); PGC.style.display = "none"; '; return $return; }); } }); you can try any one you like I left the both ways in the file This version hides some of credit card fields, but not hiding the payment methods 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 17, 2022 Share Posted December 17, 2022 (edited) if you are using paypalcheckout module you shoud repleace that in the code in the $v I have edited it for you add_hook('ClientAreaPageCart', 1, function($vars) { if ($vars['rawtotal'] == 0.00) { add_hook('ClientAreaFooterOutput', 1, function($vars) { $v = "input[value='paypalcheckout']"; $return = ' <script> document.querySelector("'.$v.'").checked = true; const PGC = document.getElementById("paymentGatewaysContainer"); PGC.style.display = "none"; </script> '; return $return; }); } }); try and tell me if it works Edited December 17, 2022 by AladdinJ I was missing </script> , fixed now 0 Quote Link to comment Share on other sites More sharing options...
Craft Posted December 17, 2022 Author Share Posted December 17, 2022 1 hour ago, AladdinJ said: you are right , I have updated it now I made it wait 1 second before hide the elements , that fixed the problem The 2nd version in the github hides the payment methods but the issue that it's still reading the credit card fields and still asking us to fill up the mandatory fields 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 17, 2022 Share Posted December 17, 2022 Yes, I realized that hiding credit card will not be useful, as entering the card details is mandatory, so I commented that code but as you mentioned choosing PayPal was a good idea I made it in the last reply from me or the first code on GitHub try and tell me if that works with you 0 Quote Link to comment Share on other sites More sharing options...
Craft Posted December 17, 2022 Author Share Posted December 17, 2022 41 minutes ago, AladdinJ said: if you are using paypalcheckout module you shoud repleace that in the code in the $v I have edited it for you add_hook('ClientAreaPageCart', 1, function($vars) { if ($vars['rawtotal'] == 0.00) { add_hook('ClientAreaFooterOutput', 1, function($vars) { $v = "input[value='paypalcheckout']"; $return = ' <script> document.querySelector("'.$v.'").checked = true; const PGC = document.getElementById("paymentGatewaysContainer"); PGC.style.display = "none"; </script> '; return $return; }); } }); try and tell me if it works I tried this code and changed the payment name to (paypal) and (paypalcheckout), but it doesn't work. The output is in this screenshot 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 17, 2022 Share Posted December 17, 2022 (edited) I tested it on my whmcs and works very well send me your whmcs url let me check something Edited December 18, 2022 by AladdinJ 0 Quote Link to comment Share on other sites More sharing options...
Craft Posted December 17, 2022 Author Share Posted December 17, 2022 (edited) 14 minutes ago, AladdinJ said: I tested it on my whmcs and works very will send me your whmcs url let me check something Perfect, I see it works now, thank you 🙂 Edited December 18, 2022 by Craft 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 18, 2022 Share Posted December 18, 2022 (edited) I see no Payment method showing up maybe you just need to clear cach in your browser Edited December 18, 2022 by AladdinJ 1 Quote Link to comment Share on other sites More sharing options...
Craft Posted December 18, 2022 Author Share Posted December 18, 2022 1 minute ago, AladdinJ said: I see no Payment method showing up maybe you just need to clear cach in your browser It works fine, thanks so much for your effort and time 🙂 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 18, 2022 Share Posted December 18, 2022 Ok good, you're welcome ❤️ 1 Quote Link to comment Share on other sites More sharing options...
FutureX Posted January 4, 2023 Share Posted January 4, 2023 Hi Aladdin, I'm trying to do the exact same thing. My payment gateway is named "Credit Card" but when I use that in this line it doesn't do anything. I see in your code to "select payment method other than credit card" not sure what to do as I don't use PayPal. $v = "input[value='Credit Card']"; My product is set to $10 and I'm using a Promo Code with a $10 value so the cart is $0 Thanks! 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted January 4, 2023 Share Posted January 4, 2023 1 hour ago, FutureX said: Hi Aladdin, I'm trying to do the exact same thing. My payment gateway is named "Credit Card" but when I use that in this line it doesn't do anything. I see in your code to "select payment method other than credit card" not sure what to do as I don't use PayPal. $v = "input[value='Credit Card']"; My product is set to $10 and I'm using a Promo Code with a $10 value so the cart is $0 Thanks! try this hook add_hook('ClientAreaPageCart', 1, function($vars) { if ($vars['rawtotal'] == 0.00) { add_hook('ClientAreaFooterOutput', 1, function($vars) { $return = ' <script> const PGC = document.getElementById("paymentGatewaysContainer"); PGC.style.display = "none"; setTimeout(function(){ const CCIF = document.getElementById("creditCardInputFields"); CCIF.style.display = "none"; }, 1000); </script> '; return $return; }); } }); try to continue placing the order not just see the section hides tell me if it works or if got problems 0 Quote Link to comment Share on other sites More sharing options...
FutureX Posted January 4, 2023 Share Posted January 4, 2023 Thanks for the help! I added the new hook. The payment section hides except for the section title "Payment Method" I'm using the Lagom 2 theme. Total Due Today is $0, when I hit checkout it tries to run and then stops with no error message and no order completion. 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted January 4, 2023 Share Posted January 4, 2023 you have any other payment gate other than credit card, as I think it's require to enter card deatils ,so if we heddin it will get an error or not be able to compte order if you hava another payment gate way ,, then we may let code swith to it , and hide the section of payment methods 0 Quote Link to comment Share on other sites More sharing options...
FutureX Posted January 4, 2023 Share Posted January 4, 2023 I don't have any other payment method right now, but I can setup a PayPal account just for this. So if the cart total is $0 then the hook will switch the payment method to PayPal and then hide it? Sounds great. 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted January 4, 2023 Share Posted January 4, 2023 4 minutes ago, FutureX said: I don't have any other payment method right now, but I can setup a PayPal account just for this. So if the cart total is $0 then the hook will switch the payment method to PayPal and then hide it? Sounds great. yes exaclty ,, any way I will try to check if there is anyway using only credit card payment method , I will tell you I rech to solution 0 Quote Link to comment Share on other sites More sharing options...
FutureX Posted January 4, 2023 Share Posted January 4, 2023 OK great, thank you! 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted January 4, 2023 Share Posted January 4, 2023 17 minutes ago, FutureX said: OK great, thank you! Thank you very much for the coffee, that's a lot, There was no need to do that, I really appreciate it ❤️ 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted January 4, 2023 Share Posted January 4, 2023 (edited) the best solution I got , you can activate payment module that called "mailin" then we make the hook when cart is Zero , showing only this payment methods and hide if from user interface Edited January 4, 2023 by AladdinJ 0 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.