Difference between revisions of "Linking to WHMCS"

From WHMCS Documentation

(Configurable Options)
 
(60 intermediate revisions by 7 users not shown)
Line 1: Line 1:
It is very common for users of WHMCS to want to link to WHMCS from their website. This can be in the form of an order link, or with a form that either takes the user straight to the domain checking process to check the availability of the domain they want or to login.
+
Linking to WHMCS is one of the first things to do after you set up WHMCS. You can create login or product links for the Client Area, a shortcut to a ticket submission form, or an order form purchase link.
  
With WHMCS, this is made easy as all the code you need is provided to you customised and ready to insert into your website by simply going to Utilities > Integration Code.
+
* For integrating a domain availability check, login form, or domain purchase link, see '''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==
+
<div class="docs-alert-info">
 +
The examples below use a WHMCS installation at <tt><nowiki>http://www.example.com/whmcs</nowiki></tt>.
 +
</div>
 +
 +
===Client Area and Shopping Cart Links===
  
You can obtain direct order links for products from the product configuration screen. A direct order link takes the user straight into step two of the order process with the product or service preselected.  This is used for order links on your site for specific products. The link looks something like this:
+
To link to the Client Area, allowing the user to manage their client account:
 +
<nowiki>http://www.example.com/whmcs/clientarea.php</nowiki>
 +
If the user is not already logged in, this link will first direct them to a login prompt.
  
  http://demo.whmcs.com/cart.php?a=add&pid=1
+
To link directly to the active shopping cart:
 +
  <nowiki>http://www.example.com/whmcs/cart.php</nowiki>
 +
This link will go directly to the default product group.
  
To link to the order process with a given product and annual billing cycle preselected, you can use a link like this:
+
==Cart and Product Links==
 
+
http://demo.whmcs.com/cart.php?a=add&pid=1&billingcycle=annually
+
The '''Links''' tab when you click '''Edit''' for a product at '''Configuration (<i class="fa fa-wrench" aria-hidden="true"></i>) > System Settings > [[Products and Services|Products/Services]]''' or, prior to WHMCS 8.0, '''Setup > Products/Services > Products/Services''' displays various links to the product. You can use these links to direct clients to a specific page or to load the product into their cart and immediately take them to the configuration step for that product.
 +
 +
===Product Link Tab Links===
 +
 +
[[File:link-tab-urls-83.png|thumb|]]
 +
 
 +
You can find the following URLs here:
 +
 
 +
* '''Direct Shopping Cart Link''' — The product is added to the shopping cart and the visitor goes directly to the configuration page, if applicable.
 +
* '''Direct Shopping Cart Link Specifying Template''' — The product is added to the shopping cart and the visitor goes directly to the configuration page using a specified template.
 +
* '''Direct Shopping Cart Link Including Domain''' — The product is added to the shopping cart and the visitor goes directly to the domain selection page.
 +
* '''Product Group Cart Link''' — The visitor goes directly to the product group page.
 +
* '''Product URLs''' — The visitor goes directly to the '''Direct Shopping Cart Link''' URL destination.
 +
** Product URLs also track the number of visits for each product URL.
 +
** When you delete a product URL, the URL will become nonfunctional.
 +
 
 +
For more information, see [[Products and Services]] and [[Friendly URLs]].
 +
 +
===Constructing Additional Links===
 +
 +
<div class="docs-alert-info">
 +
All of these examples begin with the '''Direct Shopping Cart Link''' URL described above.
 +
</div>
  
To link to the order process with a domain preselected, you can use a link like this:
+
To link to a preselected product with an annual billing cycle, add a <tt>billingcycle</tt> value:
 +
<nowiki>http://example.com/whmcs/cart.php?a=add&pid=1&billingcycle=annually</nowiki>
  
http://demo.whmcs.com/cart.php?sld=google&tld=.com
+
To link to a preselected product with a domain, add <tt>sld</tt> and <tt>tld</tt> values:
 +
  <nowiki>http://example.com/whmcs/cart.php?a=add&pid=1&sld=google&tld=.com</nowiki>
  
To link to the order process with a subdomain preselected, you can use a link like this:
+
To link to a preselected product with a subdomain, add <tt>domainoption</tt> and <tt>sld</tt> values:
 +
  <nowiki>http://example.com/whmcs/cart.php?a=add&pid=1&domainoption=subdomain&sld=google</nowiki>
  
http://demo.whmcs.com/cart.php?domainoption=subdomain&sld=google
+
To automatically apply a promotion code to the order, add a <tt>promocode</tt> value alone or with any of the cart links:
 +
  <nowiki>http://example.com/whmcs/cart.php?promocode=xxxxxxx</nowiki>
  
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 link directly to an individual product group, add a <tt>gid</tt> value with the ID of the product group, or use the URL specified at '''Configuration (<i class="fa fa-wrench" aria-hidden="true"></i>) > System Settings > [[Products and Services|Products/Services]]''' or, prior to WHMCS 8.0, '''Setup > Products/Services > Products/Services''':
 +
<nowiki> http://example.com/whmcs/cart.php?gid=1</nowiki>
  
  http://demo.whmcs.com/cart.php?promocode=xxxxxxx
+
To link to the cart and specify an order form template to use, add a <tt>carttpl</tt> value with the order form template name:
 +
  <nowiki> http://example.com/whmcs/cart.php?carttpl=boxes</nowiki>
  
You can also link directly to an individual product group like this where the gid is the ID of the group to show:
+
To link to a [[Product Bundles|product bundle]], add a <tt>bid</tt> value with the ID of the bundle:
 
+
  <nowiki> http://example.com/whmcs/cart.php?a=add&bid=X</nowiki>
  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:
 
 
 
http://demo.whmcs.com/cart.php?carttpl=boxes
 
 
 
===Configurable Options & Custom Fields===
 
 
 
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 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.
 
 
 
For example:
 
  
 +
===Configurable Options===
 +
 +
You can also create your own [[Configurable Options|configurable options]].
 +
 +
To create a configurable option URL:
 +
 +
# Step through the order process normally until you reach the product configuration step.
 +
# Right click and select '''View Source'''.
 +
# Retrieve the field names and value IDs. You can use these in your direct link URLs.
 +
 +
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>
 
+
 
<div class="cartbox">
 
<div class="cartbox">
 
<table cellspacing="0" cellpadding="0">
 
<table cellspacing="0" cellpadding="0">
Line 49: Line 87:
 
</td></tr>
 
</td></tr>
 
</table>
 
</table>
</div>
+
</div></nowiki>
</nowiki>
 
  
You would then use the URL:
+
You would then use this URL:
 +
<nowiki>http://example.com/whmcs/cart.php?a=add&pid=1&configoption[1]=100</nowiki>
 +
This would set the value of the first configurable option to <tt>100</tt>.
  
  <nowiki>http://demo.whmcs.com/cart.php?a=add&pid=1&configoption[1]=100</nowiki>
+
===Custom Fields===
 +
   
 +
Custom product fields are almost exactly the same. The following link would prefill the custom field option, the day of the week, with the value <tt>Friday</tt>:
  
This would set the value of the first configurable option to 100.
+
  <nowiki>http://example.com/whmcs/cart.php?a=add&pid=5&cf_dayofweek=Friday</nowiki>
  
Custom fields are almost exactly the same, the following would pre-fill the first custom field option with the value "Friday":
+
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, 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&customfield[1]=Friday</nowiki>
+
   <nowiki>http://example.com/whmcs/cart.php?a=add&pid=5&cf_dayofweek=Friday&skipconfig=1</nowiki>
  
==Setting the Language/Template via the URL==
+
<div class="docs-alert-info">
 
+
Custom field names must not contain any special characters other than underscores in order to prefill custom fields within a URL. For example, <tt>daté-óf-bírth</tt> becomes <tt>dateofbirth</tt>.
You can set the language or template to be displayed to the user with the link you use to WHMCS. This is done with links such as:
+
</div>
 
 
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
+
===Addons===
 +
 +
You can link to the order form with preselected addons using a URL like this:
 +
   
 +
<nowiki>http://example.com/whmcs/cart.php?a=add&pid=1&addons[1]</nowiki>
  
  http://demo.whmcs.com/cart.php?systpl=portal&language=English&gid=1
+
The number is the ID of the addon you specified.
 +
 +
You can add multiple addons in this format:
 +
 +
  <nowiki>http://example.com/whmcs/cart.php?a=add&pid=1&addons[1]&addons[2]</nowiki>
  
  http://demo.whmcs.com/cart.php?systpl=portal&language=Spanish&a=add&pid=1
+
==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:
 +
 +
<nowiki>http://example.com/whmcs/index.php?systpl=portal</nowiki>
 +
<nowiki>http://example.com/whmcs/index.php?language=Spanish</nowiki>
 +
<nowiki>http://example.com/whmcs/index.php?systpl=portal&language=Spanish</nowiki>
 +
  <nowiki>http://example.com/whmcs/cart.php?systpl=portal&language=English&gid=1</nowiki>
 +
<nowiki>http://example.com/whmcs/cart.php?systpl=portal&language=Spanish&a=add&pid=1</nowiki>
  
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 with a preselected currency (and, optionally, a language) using a URL like this:
 +
 +
'''Selecting Currency ID 1'''
 +
 +
  <nowiki>http://example.com/whmcs/cart.php?currency=1</nowiki>
  
You can link to the order form with a specific currency by simulating what the form shown for currency selection does:
+
'''Selecting Currency ID 2 and the Spanish language'''
 
+
http://demo.whmcs.com/index.php?cart.php?currency=1
+
  <nowiki>http://example.com/whmcs/cart.php?currency=2&language=Spanish</nowiki>
  
http://demo.whmcs.com/index.php?cart.php?currency=1&language=Spanish
+
The ID of a currency is the unique ID for it within the <tt>tblcurrencies</tt> database table. You can find this within the database or by examing the number at the end of the URL when editing the currency within the Admin Area.
  
 
==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.
 +
 +
To define the ticket subject, use a link like this:
 +
 +
<nowiki>http://example.com/whmcs/submitticket.php?step=2&deptid=1&subject=Subject%20goes%20here...</nowiki>
 +
You can also define a name and email address:
 +
 +
<nowiki>http://example.com/whmcs/submitticket.php?step=2&deptid=1&name=Jeff&email=jeff@example.com</nowiki>
  
You can link to the create ticket page with a number of predefined settings. All of which are interchangeable:
+
==Integrating The Login Form into your Website==
 
+
   
To define the support department, client name and email address you can use a link like this:
+
See '''Utilities > [[Integration Code]]''' in the WHMCS Admin Area for copy-and-paste ready code for adding a client's login form to any page of your site.
 
+
   
http://demo.whmcs.com/submitticket.php?step=2&deptid=1&name=Jeff&email=jeff@example.com
+
In WHMCS version 8.1 and above, enhanced security around login forms means that to leverage an external login form that posts data to <tt>dologin.php</tt>, the line below must be added to the <tt>configuration.php</tt> file:
 
 
To define the ticket subject and message, use a link like this:
 
 
 
  http://demo.whmcs.com/submitticket.php?step=2&subject=Questions&message=Your_message_here
 
 
 
==Showing Announcements on your Site==
 
 
 
You can display the announcements on any page of your site using the code below. This will display the latest 3 announcements set to published status.
 
 
 
<?php
 
include("support/dbconnect.php");
 
include("support/includes/functions.php");
 
$query = "SELECT * FROM tblannouncements WHERE published='on' ORDER BY date DESC LIMIT 0,3";
 
$result = mysql_query($query);
 
while ($data = mysql_fetch_array($result)) {
 
  $id = $data["id"];
 
  $date = $data["date"];
 
  $title = $data["title"];
 
  $announcement = $data["announcement"];
 
  <nowiki>$date = fromMySQLDate($date);
 
  echo("<p><font color=#cccccc>$date</font> - <b>$title</b><br>$announcement</p>");</nowiki>
 
}
 
?>
 
 
 
You should replace the word support in the first two lines where it includes files from the WHMCS folder with the path to your WHMCS directory.
 
 
 
==Showing The Login Form on your Site==
 
 
 
You can display the login form on any page of your site using the code belowThis will display the required login form to login to the WHMCS Client Area.  
 
  
<pre>
+
<nowiki>$allow_external_login_forms = true;</nowiki>
<form method="post" action="http://www.yourdomain.com/whmcs/dologin.php">
 
Email Address: <input type="text" name="username" size="50">
 
Password: <input type="password" name="password" size="20">
 
<input type="submit" value="Login">
 
</form>
 
</pre>
 
  
You should replace the URL of the form action to the path to your WHMCS directory.
+
==Integrating a Domain Availability Check into your Website==
 +
 +
See '''Utilities > [[Integration Code]]''' within the 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:
 +
 +
<source lang="php">
 +
<?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 />";
 +
}
 +
</source>
 +
 +
This code assumes that you store WHMCS in the <tt>members</tt> subdirectory. Update the file include path for your setup.

Latest revision as of 21:33, 28 November 2022

Linking to WHMCS is one of the first things to do after you set up WHMCS. You can create login or product links for the Client Area, a shortcut to a ticket submission form, or an order form purchase link.

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

The examples below use a WHMCS installation at http://www.example.com/whmcs.

Client Area and Shopping Cart Links

To link to the Client Area, allowing the user to manage their client account:

http://www.example.com/whmcs/clientarea.php

If the user is not already logged in, this link will first direct them to a login prompt.

To link directly to the active shopping cart:

http://www.example.com/whmcs/cart.php

This link will go directly to the default product group.

Cart and Product Links

The Links tab when you click Edit for a product at Configuration () > System Settings > Products/Services or, prior to WHMCS 8.0, Setup > Products/Services > Products/Services displays various links to the product. You can use these links to direct clients to a specific page or to load the product into their cart and immediately take them to the configuration step for that product.

Product Link Tab Links

Link-tab-urls-83.png

You can find the following URLs here:

  • Direct Shopping Cart Link — The product is added to the shopping cart and the visitor goes directly to the configuration page, if applicable.
  • Direct Shopping Cart Link Specifying Template — The product is added to the shopping cart and the visitor goes directly to the configuration page using a specified template.
  • Direct Shopping Cart Link Including Domain — The product is added to the shopping cart and the visitor goes directly to the domain selection page.
  • Product Group Cart Link — The visitor goes directly to the product group page.
  • Product URLs — The visitor goes directly to the Direct Shopping Cart Link URL destination.
    • Product URLs also track the number of visits for each product URL.
    • When you delete a product URL, the URL will become nonfunctional.

For more information, see Products and Services and Friendly URLs.

Constructing Additional Links

All of these examples begin with the Direct Shopping Cart Link URL described above.

To link to a preselected product with an annual billing cycle, add a billingcycle value:

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

To link to a preselected product with a domain, add sld and tld values:

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

To link to a preselected product with a subdomain, add domainoption and sld values:

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

To automatically apply a promotion code to the order, add a promocode value alone or with any of the cart links:

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

To link directly to an individual product group, add a gid value with the ID of the product group, or use the URL specified at Configuration () > System Settings > Products/Services or, prior to WHMCS 8.0, Setup > Products/Services > Products/Services:

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

To link to the cart and specify an order form template to use, add a carttpl value with the order form template name:

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

To link to a product bundle, add a bid value with the ID of the bundle:

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

Configurable Options

You can also create your own configurable options.

To create a configurable option URL:

  1. Step through the order process normally until you reach the product configuration step.
  2. Right click and select View Source.
  3. 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://example.com/whmcs/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, the day of the week, with the value Friday:

 http://example.com/whmcs/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, this would generate an error and force the client to edit the configuration. For example:

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

Custom field names must not contain any special characters other than 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://example.com/whmcs/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://example.com/whmcs/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://example.com/whmcs/index.php?systpl=portal
http://example.com/whmcs/index.php?language=Spanish
http://example.com/whmcs/index.php?systpl=portal&language=Spanish
http://example.com/whmcs/cart.php?systpl=portal&language=English&gid=1
http://example.com/whmcs/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://example.com/whmcs/cart.php?currency=1

Selecting Currency ID 2 and the Spanish language

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

The ID of a currency is the unique ID for it within the tblcurrencies database table. You can find this within the database or by examing the number at the end of the URL when editing the currency within the Admin Area.

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://example.com/whmcs/submitticket.php?step=2&deptid=1&subject=Subject%20goes%20here...

You can also define a name and email address:

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

Integrating The Login Form into your Website

See Utilities > Integration Code in the WHMCS Admin Area for copy-and-paste ready code for adding a client's login form to any page of your site.

In WHMCS version 8.1 and above, enhanced security around login forms means that to leverage an external login form that posts data to dologin.php, the line below must be added to the configuration.php file:

$allow_external_login_forms = true;

Integrating a Domain Availability Check into your Website

See Utilities > Integration Code within the 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.