Jump to content

Hide Payment Method section for Free Trial products


Craft

Recommended Posts

you shoud activate mailin payment module  it's called " Mail In Payment " in whmcs

make sure to activate it in products group also

then

this hook will allow only Mainin  when cart is zero and will auto choose it and hide payment gateway section ( for Logam2) 

add_hook('ClientAreaPageCart', 1, function($vars) {
    
    if ($vars['rawtotal'] == 0.00)
    {
		$gateways = $vars['gateways'];
		$allowed = ['mailin'];
		foreach ($gateways as $k => $item) {
			if (!in_array($item['sysname'],$allowed)) {
				unset($gateways[$k]);
			}
		}
		
        add_hook('ClientAreaFooterOutput', 1, function($vars) {
        $v = "input[value='mailin']";
        $return = '
<script>
    document.querySelector("'.$v.'").checked = true;
    const PGC = document.getElementById("paymentGatewaysDetails");
    PGC.style.display = "none";
</script>
    ';
        return $return;
        });
		return array("gateways" => $gateways);
    }
});


try and tell me if it works with you 

Edited by AladdinJ
fixed
Link to comment
Share on other sites

6 minutes ago, FutureX said:

Yes!  Works great!

Is there any way to do the opposite when the cart is > $0?  hide Mailin and only show Credit Card?

you are right , 

this hook will fix this

// hide mailin when cart total above zero

add_hook('ClientAreaPageCart', 1, function($vars) {
    
    if ($vars['rawtotal'] > 0.00)
    {
		$gateways = $vars['gateways'];
		$remove = ['mailin'];
		foreach ($gateways as $k => $item) {
			if (in_array($item['sysname'],$remove)) {
				unset($gateways[$k]);
			}
		}
		return array("gateways" => $gateways);
    }
});

 

Link to comment
Share on other sites

6 hours ago, AladdinJ said:

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

 

Or read the payment methods with a hook, remove the one you want and return the array back to template.

Edited by pRieStaKos
Link to comment
Share on other sites

  • 4 weeks later...
35 minutes ago, DeeeExclusive said:

Hi All

Anyone has a working hook to hide a payment methode for public only, (non logged in clients) ?

hi 
you can consider if client logged or not using this way

 

$cli = Menu::context('client');
if (!is_null($cli))
{ // the client logged in
}

 

Link to comment
Share on other sites

11 minutes ago, DeeeExclusive said:

thanks, you got the full hook?

the one from brian is not working for me 😞

ok this example will remove paypal for non logged in clients 

<?php
/**
 * Hide paymentGateways for non logged in clients
 * @package     WHMCS
 * @author      AladdinJ
 */

if (!defined("WHMCS"))
    die("This file cannot be accessed directly");


add_hook('ClientAreaPageCart', 1, function($vars) {
	$cli = Menu::context('client');
	if (is_null($cli))
    {
		$gateways = $vars['gateways'];
		$remove = ['paypal'];
		foreach ($gateways as $k => $item) {
		  if (in_array($item['sysname'],$remove)) {
		      unset($gateways[$k]);
		  }
		}
		return array("gateways" => $gateways);
    }
});

tell me it it works well with you 

Edited by AladdinJ
Link to comment
Share on other sites

12 minutes ago, DeeeExclusive said:

hmm i dont understand, its not working for me

im trying with banktransfer, and it still exist on cart.php while checking out when im not logged in

I just tested exact code I wrote for you it works with me

$remove = ['paypal'];

try replace the above line with

$remove =array("banktransfer");

 

Edited by AladdinJ
Link to comment
Share on other sites

  • 5 months later...
  • 2 weeks later...

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