Author: whmcsisg8

21 Sep

How to use Smarty if else?

Let’s assign a discount amount from PHP to the tpl file as shown below.

$smarty->assign('discount', 0); 
{if $discount gt 0}
   You have a discount and discount amount is: {$discount}
	You don't have any discount.

Now let’s assign some string to the tpl file as shown below.
Here we compare two strings equality using ‘eq’

$smarty->assign('category', 'Electronics'); 

Then in the tpl file, we can check the category as shown below.

{if $category eq 'Electronics'}
    As you are booking an electronics product, you will get a discount of 15%.
    For this product, we have a discount of 5%.

For detailed explanation regarding the usage of if else in tpl,
go to the link

21 Sep

How to use Smarty foreach?

You can pass an array to the smarty tpl file as shown below.

$user_details = array(
	"name" => "x",
	"address" => "Y",
        "phone" => "Z"
$smarty->assign('my_array', $user_details);  //my_array can be replaced with anything

Then in the tpl file you can loop through the array as shown below

   Note: We used my_array here because we passed array as
   assign('my_array', $user_details);

{foreach from=$my_array key=k item=v}
   <li>{$k}: {$v}</li>

If we are passing an array without key in it say

$user_details = array(
	"x", "y", "z"
$smarty->assign('my_array', $user_details); 

Then we can display the values in the tpl as shown below

{foreach from=$my_array item=v}
20 Sep

WHMCS Addon development

WHMCS addon can be used to develop additional features in your WHMCS.

Here briefly explaining steps required to develop a simple addon, that just print some strings.
That’s enough to get started. After developing this simple addon you can move on to complex addons.

Addon name and folder name

Name of addon do have importance while developing a WHMCS addon.
Let’s name our addon as hello_world.

Then we have to create a folder named hello_world.
Within the folder, develop a file named hello_world.php.
Name used for the folder and file is hello_world, which is the name of the addon.
We have to upload the folder to the WHMCS folder /modules/addons/.

Functions to be defined in hello_world.php

We have to define some functions in the file hello_world.php.
Prefix for those functions should be same as the addon name.
As our addon name is hello_world, prefix for those functions
must be hello_world_.

Those functions are listed below.


This function just returns an array.
Here we define addon name, version author etc.

function hello_world_config() {
    $configarray = array(
        "name" => "My first whmcs addon",
        "description" => "Just a sample addon, that just prints some strings",
        "version" => "1.0",
        "author" => "",
        "language" => "english",
    return $configarray;


This function is called when the addon module is activated from the admin side.
We can write table creation code within the function.

function hello_world_activate () {
    return array(
        'status' => 'success',
        'description' => 'Addon activated'


This function is called when we are deactivating the addon from the admin side.
All addon table drop code should be added here.

function hello_world_deactivate() {
    return array(
        'status' => 'success',
        'description' => 'Addon deactivated'


Code written within this function will be executed when we take the url

function hello_world_output($vars) {
    echo "just printing this in admin side";


This function is called when we take the url,

To display some contents in the client area, we have to create a smarty tpl file.
In the function hello_world_clientarea, we specified tpl file name as
‘templatefile’ => ‘template/clienthome’. So we have to create a folder named
template inside the folder /modules/addons/hello_world.
Then we have to create a file named clienthome.tpl in the folder template.
Note that we specified templatefile as ‘templatefile’ => ‘template/clienthome’, (no extension here) but we created file name as template/clienthome.tpl with the extension .tpl.

We have to pass parameters to the tpl file from the function hello_world_clientarea.
In the function we are passing the smarty key value pair as shown below.

'vars' => array(
            'name' => 'X ',
            'address' => 'Y',
            'phone' => 'Z',

Then in the tpl file we just have to write {$name} to display the name.

function hello_world_clientarea($vars) {
    $modulelink = $vars['modulelink'];
    return array(
        'pagetitle' => 'Addon Module',
        'breadcrumb' => array('index.php?m=hello_world'=>'Hello World Addon'),
        'templatefile' => 'template/clienthome', #smarty file name without .tpl extension
        'requirelogin' => true, # accepts true/false
        'forcessl' => false, # accepts true/false
        'vars' => array(  #smarty key value pair
            'name' => 'X ',
            'address' => 'Y',
            'phone' => 'Z',

Content of the file template/clienthome.tpl is

    <h4> My Details </h4>

        <li>My name is : {$name} </li>
       <li>My address is : {$address} </li>
        <li>My phone number is : {$phone} </li>
20 Sep

How to create and drop tables in WHMCS 7 using PHP 7?

We might have to create a table from WHMCS addon while activating the module.
Also we might have to drop the table while deactivating the module.
Here we are going to write PHP 7 compatible codes to create and drop the table.

Create a table

Assume that we have to create a table named sample_table
with the following fields.
It’s an auto increment field, also it’s primary key of the table.

This field is an integer

This field should store string and maximum character length is 100.

It’s a date field

It’s float field with two decimal points.

It’s a text field.

Then we can use below code for that.

 use Illuminate\Database\Capsule\Manager as Capsule;
 if (!Capsule::schema()->hasTable('sample_table')) {
        Capsule::schema()->create('sample_table', function($table) {
            $table->string('name', 100);
            $table->float('amount', 8, 2);

Drop the table.

To drop the table we can use the below code.

#add the below line only once in a file
use Illuminate\Database\Capsule\Manager as Capsule;
21 Aug

WHMCS Report Development

We can easily create a custom report in WHMCS.
First of all we have to create a file with any name and then we have to upload it to the folder modules/reports.

Let’s write a report to list down invoices that are paid between two dates.
Name of the file is invoice_report.php.
And it should be uploaded to the folder, modules/reports.

Th sample report code is below.


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

use Illuminate\Database\Capsule\Manager as Capsule;

# Report Title
$reportdata["title"] = "Invoice Report";

# Report Description
$reportdata["description"] = "";

$start_date = "2017-01-01";
$end_date =  date("Y-m-d");  

$reportdata["tableheadings"] = array(
      "DATE PAID", 
 if(!empty($start_date) && !empty($end_date)) {
        $invoices = Capsule::table('tblinvoices')
              ->whereBetween('datepaid', array($start_date, $end_date))
              ->where('status', 'Paid')

        foreach($invoices as $invoice) {
	         $reportdata["tablevalues"][] = array(
                    $invoice->tax + $invoice->tax2,

We have a ready made sales total report tool, with one time cost of $25.
Please Contact Us by filling the form. We will get back to you asap.

31 Jul

How to render button in Django base table?

Assume that you have a table as defined below

class CustomerTable(BaseTable):
    pk = ToggleColumn()
    name = tables.LinkColumn('customers:customer', args=[Accessor('')])

    class Meta(BaseTable.Meta):
        model = Customer
        fields = ('pk', 'name',  'city', 'state' , 'phone')

Now assume you would like to display a button next to the phone

we can do it as below

class CustomerTable(BaseTable):
    pk = ToggleColumn()
    name = tables.LinkColumn('customers:customer', args=[Accessor('')])
    edit_button = tables.Column(empty_values=())

    class Meta(BaseTable.Meta):
        model = Customer
        fields = ('pk', 'name',  'city', 'state' , 'phone', 'edit_button')

    def render_edit_button(self, record):
        rendered_item = format_html(
            "<a href='{url}' class='btn btn-primary' role='button'>Edit</a>",
            url= reverse('users:user_edit', kwargs={'id'})
        return rendered_item
19 Jul

Useful Linux Tips

#Replace all occurrence of City with Town in every txt file within the current directory.
$sed -i 's/City/Town/g' *.txt

Using vim editor, replace foo with bar from line 23 to 30

19 Jul

Useful git commands

#remove files only from local, not from git
$git rm -r --cached myfolder/

#reset back to the head
$git reset --hard my_branch

#make a branch same as master
$git checkout -B new master

#Delete local branch
$git branch -d branch_name

#push a new local branch to remote
$git push -u origin my_branch

#ignore file mode change
$git config core.fileMode false

19 Jul

Useful PostgreSQL Queries and Commands

Connecting as root
$sudo -u postgres psql

Connect to database server:
$psql --username=myusername --host=localhost --password

Select a database with name mydatabase:
myusername=>\c mydatabase;

List all tables:

Get table structure:
myusername=>\d+ my_table;

Take a dump
$pg_dump --username=myusername --host=localhost --password mydatabase > db.sql

Import a database
$psql --username=myusername --host=localhost --password mydatabase < db.sql

5 Jul

Multi Level Product Category (Product Subcategory) in WHMCS

By default in WHMCS, only one level product categories are possible. Assume that you have a category
US and another Category Spain. And under US you have another category California Items
and Under Spain you have another category named Madrid Items.

Then currently you have to create two categories named California Items and Madrid Items as two categories. Then you can add products under California Items and Madrid Items. But there is no way to add subcategory in WHMCS. We developed a module, which allow to add a parent category and then number of child category to it.Anybody looking for such a module, please contact.