Jump to content

Tip: How to display prices etc on non-WHMCS pages


Recommended Posts

Here is some code showing how to grab price and options info from the database and display it automatically, without the need to re-code your pages whenever you change product price or other settings. This is a pre-Widgets solution and so works with versions earlier than v4.4.

 

I decided to post this as a "How To" because while there are some useful posts on this area most were incomplete or not general enough and it seems like a common requirement. For example, I am grateful for the following thread which I borrowed heavily from: http://forum.whmcs.com/showthread.php?t=23273

 

My simplified code below should help people adapt this approach to their application more easily. If you save it as PHP and edit the paths in the "require" statements it renders a page with two tables. One of your domain registration pricing, and one showing your hosting plans in each currency. For example:

 

Domain Pricing

Extension	Price
.co.uk	£0.00
.co.uk	£0.00
.com	£8.45
.com	£13.49
.org	£8.45
.org	£13.49
.net	£8.45
.net	£13.49
.eu	£16.95
.eu	£26.95

Hosting Plans

Hosting Plan	Pay Monthly	Pay Annually
Freelance/Practitioner	£3.99	£39.95/year (£3.33/month)
Freelance/Practitioner	$6.99	$67.95/year ($5.66/month)
Fully Managed Hosting (Freelance/Practitioner)	N/A	£97.00/year (£8.08/month)
Fully Managed Hosting (Freelance/Practitioner)	N/A	$169.00/year ($14.08/month)
Freelance/Practitioner	€4.99	€49.95/year (€4.16/month)
Fully Managed Hosting (Freelance/Practitioner)	N/A	€125.00/year (€10.42/month)
Professional	£7.49	£79.95/year (£6.66/month)
Professional	$12.99	$139.95/year ($11.66/month)
Professional	€9.99	€99.95/year (€8.33/month)
Corporate	£9.99	£99.95/year (£8.33/month)
Corporate	$16.99	$169.95/year ($14.16/month)
Corporate	€12.99	€124.95/year (€10.41/month)

All Group & Plan Settings
<snipped>

 

These are followed by output of more detail information on all your plans (not shown to keep the length of this post managable!). Anyway, here's the code which is fairly self explanatory:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
</head>
<body>
<?php

# WHMCS functions (note ./clients is the location of the WHMCS folder)
require("clients/dbconnect.php");
require("clients/includes/functions.php");
require("clients/includes/clientareafunctions.php");
require("clients/includes/currencyfunctions.php");

####################################################
# Domain Pricing Table
#
# This list prices in the -default- currency only
echo "<h2>Domain Pricing</h2>";

$result = mysql_query("
SELECT * FROM tblpricing 
LEFT JOIN tbldomainpricing 
ON tblpricing.relid = tbldomainpricing.id
WHERE tblpricing.type = 'domainregister'
") or die(mysql_error()); 

echo "<table width='300' border='0' class='mytable'>";
echo "<tr><th>Extension</th><th>Price</th></tr>";

while($row = mysql_fetch_array($result)){
echo "<tr><td>"; 
echo $row['extension'];
echo "</td><td>"; 
echo "£";
echo $row['msetupfee'];
echo "</td></tr>";
} 
echo "</table>"; 

####################################################
# HOSTING PLAN TABLE
#
# This lists prices in -all- currencies.
echo "<h2>Hosting Plans</h2>";

$result = mysql_query("
SELECT p.name, p.description, t.monthly, t.quarterly, 
	t.semiannually, t.annually, c.code 
FROM tblproducts AS p
INNER JOIN tblpricing AS t ON t.type='product' AND t.relid = p.id 
INNER JOIN tblcurrencies AS c ON c.id = t.currency
WHERE p.hidden != 'on' AND p.type ='hostingaccount'
") or die(mysql_error()); 

// Used to map database code to currency symbol
$currency_symbol = array(
'USD' => '$',
'GBP' => '&pound',
'EUR' => '€' // Euro (see http://www.cs.tut.fi/~jkorpela/html/euro.html)
);

echo "<table width='300' border='0'>";
echo "<tr valign=top>
<th>Hosting Plan</th>
<th>Pay Monthly</th>
<th>Pay Annually</th>
</tr>";

while($row = mysql_fetch_array($result)){
echo "<tr valign=top>";
echo "<td>" . $row['name'] . "</td>";

// Some plans are not available monthly
if ($row['monthly'] < 0)
	echo "<td>N/A</td>";
else
	echo "<td>" . $currency_symbol[$row['code']] . $row['monthly'] . "</td>";

	echo "<td>" . $currency_symbol[$row['code']] . $row['annually'] . "/year (" . $currency_symbol[$row['code']] . round($row['annually']/12,2) . "/month)</td>";
echo "</tr>";
} 
echo "</table>"; 

#######################################################
# This shows how to get all settings for Groups & Plans
#
echo "<h2>All Group & Plan Settings</h2>";

echo "<b>Groups</b><br/>";
$whmcs_group_number = 0;

$result_groups = mysql_query("
SELECT DISTINCT tblproducts.gid, tblproductgroups.id, tblproductgroups.name, 
	tblproductgroups.order, tblproducts.type, tblproductgroups.hidden, 
	tblproducts.hidden FROM tblproductgroups, tblproducts 
WHERE tblproducts.gid = tblproductgroups.id 
AND tblproducts.type = 'hostingaccount' 
AND tblproducts.hidden != 'on' 
AND tblproductgroups.hidden != 'on' 
ORDER BY tblproductgroups.order ASC
") or die(mysql_error()); 

while($row = mysql_fetch_assoc($result_groups)){
// populate multi-level array with individual hosting group details
echo "<br/>";
foreach ($row as $key => $value){
	echo "$whmcs_group_number $key: $value<br/>"; // Debug
	$whmcs_hosting_groups["$whmcs_group_number"]["$key"] = $value;
}
$whmcs_group_number++;
}

echo "<br><b>Plans</b><br/>";
$default_currency='1';
$groupid='1';

# get a list of plans and store them in an array for Smarty
$result = mysql_query("
SELECT *, tblproducts.name AS prodname, tblproducts.id AS prodid 
FROM tblproducts, tblproductgroups, tblpricing 
WHERE tblpricing.type = 'product' 
AND tblproducts.id = tblpricing.relid 
AND tblpricing.currency = '$default_currency' 
AND tblproducts.gid=tblproductgroups.id 
AND tblproducts.type='hostingaccount' 
AND (tblproducts.hidden != 'on' AND tblproductgroups.hidden != 'on') 
AND tblproducts.gid='$groupid' ORDER BY tblproducts.id ASC
") or die(mysql_error()); 

$whmcs_plan_number = 0;

while($row = mysql_fetch_assoc($result)){
$whmcs_plans[] = $row; # $data is the array created for use in the Smarty template.

// populate multi-level array with individual hosting package details
echo "<br/>";
foreach ($row as $key => $value){
	echo "$key: $value<br/>"; // Debug
	$whmcs_plans_feature["$whmcs_plan_number"]["$key"] = $value;
}

$whmcs_plan_number++;
$num_plans++;
}

echo "<br/>Total Plans: $num_plans<br/>";
?> 

 

I haven't gone live yet, but sometime in the next few days you'll be able to see the end result at Managed Website Hosting

 

Mark

Link to comment
Share on other sites

I have a script that shows prices in 3 currencies (but can be in all curencies), and when client clicks "buy now" currency is selected automatically depending their country (MXN for México, EUR for Spain, USD for other countries)

you can see it at Hosteris.com

*sorry for my bad english

Link to comment
Share on other sites

Hi @BotHaTe,

 

I'd like to use such a script to set the initial default sometime - for info, when I tried your site it stayed with USD but I'm in London UK.

 

As for my code above it is working a treat (though still not public yet - but will be visible at my Managed Website Hosting site soon). I have a simple dropdown populated with currency's I support and control the prices shown using a little CSS and jQuery. None of this requires going to WHMCS (all currency prices are there in the page but only the chosen currency is displayed) so switching currencies is instant.

 

Mark

Link to comment
Share on other sites

a little suggestion on the SQL above

 

{remove]

$result = mysql_query("

SELECT * FROM tblpricing

LEFT JOIN tbldomainpricing

ON tblpricing.relid = tbldomainpricing.id

WHERE tblpricing.type = 'domainregister'

") or die(mysql_error());

 

{Add}

$result = mysql_query("

SELECT * FROM tblpricing

LEFT JOIN tbldomainpricing

ON tblpricing.relid = tbldomainpricing.id

WHERE tblpricing.type = 'domainregister' AND tbldomainpricing.id IS NOT NULL

") or die(mysql_error());

Link to comment
Share on other sites

Hello,

i am trying to include this in a joomla article using a plugin which allows you to embed a php file but i get

Down for Maintenance

An upgrade is currently in progress... Please come back soon...

 

If i call the file directly it works.

Any clue?

thank you

Link to comment
Share on other sites

  • 1 month later...
Only issue with Widgets is that they are JS and may not display prices on all clients computers.

 

You answered your own question, While it is rightly so that a widget will be easier to use not all browsers have javascript enabled, granted it is far less common than you may think but its still a problem.

 

The only thing i can contribute here however is this. If you are going to turn away from widgets and code your own pages then think about your client base. Who are they.. mostly website designers, programers and such.

 

Now think about their job, most often than not they ARE going to have javascript enabled. I mean they want to build the perfect website. That means dynamic and graphically appealing along with other factors ofcourse.

 

Now will you still turn away from those javascript widgets? they are designed to help you out after all and let you concentrate on your MAIN objective.

 

Running your business

Link to comment
Share on other sites

mysql_error()

 

Great to see you catching errors. just dont do this in production, for development its fine but in production you may be throwing out potential security information with the mysql errors. better to log the errors for production than display them.

Link to comment
Share on other sites

  • 2 weeks later...
  • 5 weeks later...
I have a script that shows prices in 3 currencies (but can be in all curencies), and when client clicks "buy now" currency is selected automatically depending their country (MXN for México, EUR for Spain, USD for other countries)

you can see it at Hosteris.com

*sorry for my bad english

 

I looked at hosteris.com and it looks great. I see you are using Joomla. How did you integrate WHMCS with Joomla and home page looks great too.

Link to comment
Share on other sites

  • 1 year later...
Is this what you are looking for?

 

http://wiki.whmcs.com/Widgets

 

The Widgets in WHMCS are a dynamic way for extracting data from WHMCS for use on the pages of your website.

 

The widgets in documentation don't seem to have the one liner

I see they say you can use widgets to display stuff on your website but can't find the explanation of how?

 

The wiki link seems to be no more?

Link to comment
Share on other sites

  • 2 weeks later...
How did you integrate WHMCS with Joomla and home page looks great too.

this may not be how he did it, but there is a Joomla / WHMCS integration package -

 

https://www.gohigheris.com/products/jwhmcs-integrator

 

i've never used it, so I can't comment on it either way, but I came across it on another site and your question jogged my memory.

Link to comment
Share on other sites

  • 3 weeks later...
Is there a Wordpress / WHMCS integration package available?

 

So far, I've found three WordPress plugins for integrating WHMCS into WordPress:

 

  1. Integrator 3
    http://wordpress.org/extend/plugins/integrator3/
     
  2. WHMCS Bridge
    http://wordpress.org/extend/plugins/whmcs-bridge/
    http://www.whmcs.com/appstore/810/Wordpress-Bridge.html
    http://go.zingiri.com/index.php
    https://go.zingiri.com/cart.php?gid=4
     
  3. WHMCS WordPress Integration
    http://www.whmcs.com/appstore/484/WHMCS-WordPress-Integration.html
    http://premium.wpmudev.org/project/whmcs-wordpress-integration/

 

I'll be sure to add WordPress plugins as I find others (and to share my experience with each as I sample them).

 

HTH,

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated