Jump to content

Hide Payment Method section for Free Trial products


Craft

Recommended Posts

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?

 

Free Trial.png

Link to comment
Share on other sites

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.

 

Credit Card fields still exist.png

Edited by Craft
Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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

mandatory fields.png

Link to comment
Share on other sites

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

half fields.png

Link to comment
Share on other sites

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 by AladdinJ
I was missing </script> , fixed now
Link to comment
Share on other sites

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

 

182112100_mandatoryfields.png.d4835a134ee6d117e1d7cc5229f7b0dc.png

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

796208912_halffields.png.f2d2eed4bef617e1a037ab7364b618fe.png

Link to comment
Share on other sites

  • 3 weeks later...

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!

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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.

 

Screen Shot 2023-01-03 at 8.25.45 PM.png

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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 

Link to comment
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