Page 1 of 2 12 LastLast
Results 1 to 15 of 26

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

  1. #1
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    27

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

    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:

    Code:
    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:

    PHP Code:
    <!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 
    "&pound;";
        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 &amp; 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

  2. #2
    Join Date
    Jul 2008
    Posts
    96

    Default

    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

  3. #3
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    27

    Default

    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

  4. #4
    Join Date
    Mar 2008
    Location
    New Smyrna Beach, FL US
    Posts
    256

    Default

    This is alright if the files are owned by the same user. But, no so great if the site is not located within the same user that hosts whmcs script.
    StrikeHawk eCommerce, Inc.
    open source e-commerce developer on the osCommerce platform. ADD us to youtube youtube channel

  5. #5
    Join Date
    Mar 2011
    Posts
    11

    Default

    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());

  6. #6
    Join Date
    Aug 2007
    Location
    Peireus
    Posts
    70

    Default

    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

  7. #7
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    27

    Default

    @Giannis,

    That seems to be an issue with Joomla or the plugin so you would be better taking the question to a forum with people who know about them. I can't help, sorry.

    Mark

  8. #8
    Join Date
    Mar 2011
    Posts
    7

    Default

    There's a one line javascript code in the Wiki so why would you use that?

  9. #9
    Join Date
    Aug 2007
    Location
    Peireus
    Posts
    70

    Default

    can you point a link to that?
    i was looking but no luck
    thnx

  10. #10
    Join Date
    Apr 2011
    Posts
    1

    Default Widgets in WHMCS

    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.

  11. #11

    Default

    its under Utilities > Link Integration in WHMCS Control Panel

  12. #12
    Join Date
    Nov 2009
    Location
    Newquay, Cornwall UK
    Posts
    447

    Default

    You can use Widgets, why is this so long winded? Only issue with Widgets is that they are JS and may not display prices on all clients computers.

  13. #13
    Join Date
    Feb 2010
    Location
    United Kingdom
    Posts
    608

    Default

    Quote Originally Posted by bdigitalstudios View Post
    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

  14. #14
    Join Date
    Feb 2010
    Location
    United Kingdom
    Posts
    608

    Default

    Quote Originally Posted by theWebalyst View Post
    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.

  15. #15
    Join Date
    Jul 2010
    Posts
    779

    Default

    It's worth mentioning that it's not possible to order via WHMCS without javascript (at least on the web20cart) because the order buttons use javascript (onclick).

    Jakc
    Web hosting templates Responsive WHMCS & Wordpress + WHMCS templates | WHMCS Services

Page 1 of 2 12 LastLast

Similar Threads

  1. Display prices in Joomla!
    By ilihost in forum Commercial Modules and Addons
    Replies: 0
    Last Post: 11-27-09, 07:02 PM
  2. Display prices without login
    By pingelmonster in forum Customisation and Integration Questions
    Replies: 2
    Last Post: 11-24-09, 02:02 PM
  3. Showing prices on custom pages
    By Neil-UKWSD in forum Technical Issues and Questions
    Replies: 6
    Last Post: 10-30-09, 12:17 AM
iron-diatonic