Remove payment options for free products in WHMCS 5

WHMCS by default requires that every order has a payment type associated with it regardless whether the order is free or not. This means that the default functionality of WHMCS is to display the payment options on the checkout form every time. This can be very confusing for a customer that expects a free product, but then is required to select a payment type.

On a current project that I am a part of, I had to remove the payment options for free checkouts. It turned out to be quite simple.

The Concept

The idea is to put a <div> around the payment options and set style=”display:none;” on the div if the order total is zero.

The Solution

In my project, I was using the Web20cart theme for the checkout pages. The concept will work for any of the cart themes that come with WHMCS and probably with any custom theme as well.

InĀ templates/orderforms/web20cart/viewcart.tpl, find the code block that looks like this:

<h2>{$LANG.orderpaymentmethod}</h2>
  <div class="cartbox">{foreach key=num item=gateway from=$gateways}
    <label><input type="radio" name="paymentmethod" value="{$gateway.sysname}" onclick="{if $gateway.type eq "CC"}showCCForm(){else}hideCCForm(){/if}"{if $selectedgateway eq $gateway.sysname} checked{/if} /> {$gateway.name}</label>
    {/foreach}</div>

Put the codeblock inside a <div> that has a trigger for the style=”display:none;” attribute, so the payment options are hidden if the order total is zero dollars.

<div {if intval(substr($total,1,-4)) == 0}style="display:none;"{/if}>
  <h2>{$LANG.orderpaymentmethod}</h2>
  <div class="cartbox">{foreach key=num item=gateway from=$gateways}
    <label><input type="radio" name="paymentmethod" value="{$gateway.sysname}" onclick="{if $gateway.type eq "CC"}showCCForm(){else}hideCCForm(){/if}"{if $selectedgateway eq $gateway.sysname} checked{/if} /> {$gateway.name}</label>
    {/foreach}</div>
</div>

  1. bas says:

    Its not working for me….

    When i insert the code payment methods will be hidden, but also when total 0 >

    I use modern theme, but dont think that is causing the problem…

    Any ideas??

    • Joonas says:

      In the modern theme, the payment options are already wrapped in a >div<, so you can just add the if-block to that on line #223 so it looks like:

      <div class="signupfields padded" {if intval(substr($total,1,-4)) == 0}style="display:none;"{/if}>

      That should do the trick. If it hides the payment options even when the order total is over zero, try outputting the value of $total and make sure doing the substring on the value is always going to return the price.

      The substring is done because, at least in the web20cart, the $total contains a value like “$0.00 USD” or “$123.99 USD” and we want to just grab the number so we can evaluate if it equals zero. I suppose the value can vary on different themes.

  2. Bas says:

    it will not work when i, insert the code like that.

    I dont have the knowledge to understand your explanation..

    Could you have a look of the modern theme?

  1. There are no trackbacks for this post yet.