Difference between revisions of "Linking to WHMCS"

From WHMCS Documentation

(DOCS-6961)
Line 1: Line 1:
Linking to your WHMCS system, be it 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.  And it's both very easy, and very flexible with WHMCS.  In this article we demonstrate some of the common links & techniques you might want to make use of.
+
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 WHMCSWHMCS makes this very easy and very flexible.
  
For integrating a domain availability check, login form or domain purchase link, please 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.
+
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==
 
==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 with the product or service preselectedThis is used for order links on your site for specific products. The link looks something like this:
+
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
 
  http://demo.whmcs.com/cart.php?a=add&pid=1
  
To link to the order process with a given product and annual billing cycle preselected, you can use a link like this:
+
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
 
  http://demo.whmcs.com/cart.php?a=add&pid=1&billingcycle=annually
  
To link to the order process with a domain preselected, you can use a link like this:
+
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
 
  http://demo.whmcs.com/cart.php?a=add&pid=1&sld=google&tld=.com
  
To link to the order process with a subdomain preselected, you can use a link like this:
+
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
 
  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 it's own the link would look like this:
+
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
 
  http://demo.whmcs.com/cart.php?promocode=xxxxxxx
  
You can also link directly to an individual product group like this where the gid is the ID of the group to show:
+
You can also link directly to an individual product group, where the <tt>gid</tt> is the ID of the group to show:
  
 
  http://demo.whmcs.com/cart.php?gid=1
 
  http://demo.whmcs.com/cart.php?gid=1
  
To link to the cart and specify a specific order form template to use, the link would be like this where boxes is the template to display:
+
To link to the cart and specify an order form template to use, you can use a link like this, where <tt>boxes</tt> is the template to display:
  
 
  http://demo.whmcs.com/cart.php?carttpl=boxes
 
  http://demo.whmcs.com/cart.php?carttpl=boxes
  
To link to a [[Product Bundles|Product Bundle]] where bid is the ID of the bundle use:
+
To link to a [[Product Bundles|Product Bundle]], where <tt>bid</tt> is the ID of the bundle use:
  
 
   http://www.yourdomain.com/whmcs/cart.php?a=add&bid=X
 
   http://www.yourdomain.com/whmcs/cart.php?a=add&bid=X
Line 40: Line 40:
 
===Configurable Options===
 
===Configurable Options===
  
There are many further options you can use, such as your own [[Addons_and_Configurable_Options|configurable options]]. The simplest way of formulating a url is to step through the order process as normal to the product configuration step, then right click > view source and get the field names and value IDS. These can then be used in your direct link URLs.
+
There are many further options you can use, such as your own [[Addons_and_Configurable_Options|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:  
 
For example:  
  
 
  <nowiki><p class="cartsubheading">Configurable Options</p>
 
  <nowiki><p class="cartsubheading">Configurable Options</p>
<p>This product/service has some options which you can choose from below to customise your
+
<p>This product or service has some options that you can choose to customise your
 
order.</p>
 
order.</p>
  
Line 57: Line 57:
 
</nowiki>
 
</nowiki>
  
You would then use the URL:
+
You would then use this URL:
  
 
  <nowiki>http://demo.whmcs.com/cart.php?a=add&pid=1&configoption[1]=100</nowiki>
 
  <nowiki>http://demo.whmcs.com/cart.php?a=add&pid=1&configoption[1]=100</nowiki>
Line 65: Line 65:
 
===Custom Fields===
 
===Custom Fields===
  
Custom product fields are almost exactly the same, the following would pre-fill the custom field option named "Day of Week" with the value "Friday":
+
Custom product fields are almost exactly the same. The following link would prefill the custom field option, "Day of Week", with the value "Friday":
  
 
   <nowiki>http://demo.whmcs.com/cart.php?a=add&pid=5&cf_dayofweek=Friday</nowiki>
 
   <nowiki>http://demo.whmcs.com/cart.php?a=add&pid=5&cf_dayofweek=Friday</nowiki>
  
It's possible to skip the configuration page entirely provided you have defined all the configuration values in the URL by adding &skipconfig=1 to your order URL. If there is any configuration missing, then this would generate an error and force the client to edit the configuration. eg:
+
It's possible to skip the configuration page entirely if you have defined all the configuration values in the URL by adding <tt>&skipconfig=1</tt> 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:
  
 
   <nowiki>http://demo.whmcs.com/cart.php?a=add&pid=5&cf_dayofweek=Friday&skipconfig=1</nowiki>
 
   <nowiki>http://demo.whmcs.com/cart.php?a=add&pid=5&cf_dayofweek=Friday&skipconfig=1</nowiki>
  
<div class="docs-alert-info">Custom field names must not contain any special characters, with the exception of underscores, in order to pre-fill custom fields within a URL. Eg. ''daté-óf-bírth'' becomes ''dateofbirth''</div>
+
<div class="docs-alert-info">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''.</div>
  
 
===Addons===
 
===Addons===
  
You can link to the order form pre-selecting addons using a url format as follows:  
+
You can link to the order form with preselected addons using a URL like this:  
  
 
  <nowiki>http://demo.whmcs.com/cart.php?a=add&pid=1&addons[1]</nowiki>
 
  <nowiki>http://demo.whmcs.com/cart.php?a=add&pid=1&addons[1]</nowiki>
  
The number is the ID of the addon being specified.
+
The number is the ID of the addon you specified.
  
Multiple addons can be added in this format:
+
You can add multiple addons in this format:
  
 
  <nowiki>http://demo.whmcs.com/cart.php?a=add&pid=1&addons[1]&addons[2]</nowiki>
 
  <nowiki>http://demo.whmcs.com/cart.php?a=add&pid=1&addons[1]&addons[2]</nowiki>
  
==Setting the Language/Template via the URL==
+
==Setting the Language or Template via the URL==
  
You can set the language or template to be displayed to the user with the link you use to WHMCS.  Here are some examples:
+
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?systpl=portal
Line 97: Line 97:
 
  http://demo.whmcs.com/cart.php?systpl=portal&language=Spanish&a=add&pid=1
 
  http://demo.whmcs.com/cart.php?systpl=portal&language=Spanish&a=add&pid=1
  
These can be combined, used on any page and used with the direct order links
+
You can combine these, use them on any page, and use them with the direct order links.
  
 
==Specifying Currency in a link==
 
==Specifying Currency in a link==
  
You can link to the order form pre-selecting a specific currency (and optionally also a language) using a url format as follows:
+
You can link to the order form with a preselected currency (and, optionally, a language) using a URL like this:
  
 
'''Selecting Currency ID 1'''
 
'''Selecting Currency ID 1'''
Line 113: Line 113:
 
==Support Ticket Links==
 
==Support Ticket Links==
  
You can link to the create ticket page with a number of predefined settings. All of which are interchangeable:
+
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:
 
To define the ticket subject, use a link like this:
Line 119: Line 119:
 
   http://demo.whmcs.com/submitticket.php?step=2&deptid=1&subject=Subject%20goes%20here...
 
   http://demo.whmcs.com/submitticket.php?step=2&deptid=1&subject=Subject%20goes%20here...
  
You can also go even further and define a name and email address too if you want:
+
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
 
  http://demo.whmcs.com/submitticket.php?step=2&deptid=1&name=Jeff&email=jeff@example.com
 
  
 
==Integrating The Login Form into your Website==
 
==Integrating The Login Form into your Website==
  
Please refer to '''Utilities > Integration Code''' within your WHMCS admin area for "copy & paste" ready code for adding a clients login form to any page of your site.
+
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==
 
==Integrating a Domain Availability Check into your Website==
  
Please refer to '''Utilities > Integration Code''' within your WHMCS admin area for "copy & paste" ready code for adding a domain lookup form to any page of your site.
+
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==
 
==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.
+
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 possible way of doing this.
+
For convenience, on a local site, you may wish to retrieve announcements directly from the database.  The following code sample demonstrates one method:
  
 
<source lang="php">
 
<source lang="php">
Line 166: Line 165:
 
</source>
 
</source>
  
This code assumes WHMCS is located in a sub-directory named "members".  You should update the file include path for your setup.
+
This code assumes that you store WHMCS in the "members" subdirectoryUpdate the file include path for your setup.

Revision as of 20:46, 29 April 2020

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.