Linking to WHMCS

From WHMCS Documentation

Revision as of 20:46, 29 April 2020 by SarahK (talk | contribs)

Linking to your WHMCS system, whether it's a login link for the client area, a shortcut to a ticket submission form, or an order form purchase link, is probably one of the first things you'll want to do after setting up WHMCS. WHMCS makes this very easy and very flexible.

For integrating a domain availability check, login form, or domain purchase link, refer to Utilities > Integration Code within your WHMCS admin area for copy-paste ready code. You may also want to refer to the Data Feeds functionality.

Order Links

You can obtain direct order links for products from the product configuration screen under Setup > Products/Services > Products/Services > Edit > Links tab. A direct order link takes the user straight into step two of the order process and preselects the product or service. Use this for order links on your site for specific products. The link looks like this:

http://demo.whmcs.com/cart.php?a=add&pid=1

To link to the order process with a preselected product and annual billing cycle, you can use a link like this:

http://demo.whmcs.com/cart.php?a=add&pid=1&billingcycle=annually

To link to the order process with a preselected domain, you can use a link like this:

http://demo.whmcs.com/cart.php?a=add&pid=1&sld=google&tld=.com

To link to the order process with a preselected subdomain, you can use a link like this:

http://demo.whmcs.com/cart.php?a=add&pid=1&domainoption=subdomain&sld=google

To automatically apply a promotion code to the order, you can append &promocode=xxxx to any of the cart links, but on its own the link would look like this:

http://demo.whmcs.com/cart.php?promocode=xxxxxxx

You can also link directly to an individual product group, where the gid is the ID of the group to show:

http://demo.whmcs.com/cart.php?gid=1

To link to the cart and specify an order form template to use, you can use a link like this, where boxes is the template to display:

http://demo.whmcs.com/cart.php?carttpl=boxes

To link to a Product Bundle, where bid is the ID of the bundle use:

 http://www.yourdomain.com/whmcs/cart.php?a=add&bid=X


Configurable Options

There are many further options you can use, such as your own configurable options. The simplest way of formulating a URL is to step through the order process as normal until you reach the product configuration step. Then, right click and select view source. Then, retrieve the field names and value IDs. You can use these in your direct link URLs.

For example:

<p class="cartsubheading">Configurable Options</p>
<p>This product or service has some options that you can choose to customise your
order.</p>

<div class="cartbox">
<table cellspacing="0" cellpadding="0">
<tr><td>Disk Space:</td><td width="5"></td><td>
<input type="text" name="configoption[1]" value="100" size="5"> x 1MB $0.00USD
</td></tr>
</table>
</div>

You would then use this URL:

http://demo.whmcs.com/cart.php?a=add&pid=1&configoption[1]=100

This would set the value of the first configurable option to 100.

Custom Fields

Custom product fields are almost exactly the same. The following link would prefill the custom field option, "Day of Week", with the value "Friday":

 http://demo.whmcs.com/cart.php?a=add&pid=5&cf_dayofweek=Friday

It's possible to skip the configuration page entirely if you have defined all the configuration values in the URL by adding &skipconfig=1 to your order URL. If there is missing configuration data, then this would generate an error and force the client to edit the configuration. For example:

 http://demo.whmcs.com/cart.php?a=add&pid=5&cf_dayofweek=Friday&skipconfig=1
Custom field names must not contain any special characters, with the exception of underscores, in order to prefill custom fields within a URL. For example, daté-óf-bírth becomes dateofbirth.

Addons

You can link to the order form with preselected addons using a URL like this:

http://demo.whmcs.com/cart.php?a=add&pid=1&addons[1]

The number is the ID of the addon you specified.

You can add multiple addons in this format:

http://demo.whmcs.com/cart.php?a=add&pid=1&addons[1]&addons[2]

Setting the Language or Template via the URL

You can set the language or template to display to the user with the link you use. Here are some examples:

http://demo.whmcs.com/index.php?systpl=portal
http://demo.whmcs.com/index.php?language=Spanish
http://demo.whmcs.com/index.php?systpl=portal&language=Spanish
http://demo.whmcs.com/cart.php?systpl=portal&language=English&gid=1
http://demo.whmcs.com/cart.php?systpl=portal&language=Spanish&a=add&pid=1

You can combine these, use them on any page, and use them with the direct order links.

Specifying Currency in a link

You can link to the order form with a preselected currency (and, optionally, a language) using a URL like this:

Selecting Currency ID 1

http://demo.whmcs.com/cart.php?currency=1

Selecting Currency ID 2 and the Spanish language

http://demo.whmcs.com/cart.php?currency=2&language=Spanish

Support Ticket Links

You can link to the create ticket page with a number of predefined settings, all of which are interchangeable:

To define the ticket subject, use a link like this:

 http://demo.whmcs.com/submitticket.php?step=2&deptid=1&subject=Subject%20goes%20here...

You can also define a name and email address:

http://demo.whmcs.com/submitticket.php?step=2&deptid=1&name=Jeff&email=jeff@example.com

Integrating The Login Form into your Website

Refer to Utilities > Integration Code within your WHMCS admin area for copy-and-paste ready code for adding a client's login form to any page of your site.

Integrating a Domain Availability Check into your Website

Refer to Utilities > Integration Code within your WHMCS admin area for copy-and-paste ready code for adding a domain lookup form to any page of your site.

Displaying Announcements on your Site

Announcements are available in RSS feed format. This is the recommended way of retrieving and displaying announcements in an external system or page.

For convenience, on a local site, you may wish to retrieve announcements directly from the database. The following code sample demonstrates one method:

<?php
 
use WHMCS\Database\Capsule;
 
require_once 'members/init.php';
 
$data = Capsule::table('tblannouncements')
            ->where('published', '!=', '0')
            ->where('published', '!=', '')
            ->orderBy('date', 'DESC')
            ->limit(3)
            ->get();
 
foreach ($data as $announcement) {
    $id = $announcement->id;
    $date = $announcement->date;
    $title = $announcement->title;
    $body = $announcement->announcement;
 
    $date = fromMySQLDate($date);
 
    echo "<strong>{$title}</strong><br />"
        . "Posted on {$date}<br /><br />"
        . $body . "<br /><br />";
}

This code assumes that you store WHMCS in the "members" subdirectory. Update the file include path for your setup.