Jump to content

Wordpress - WHMCS Products integration.


Recommended Posts

Hi,

We would like to retrieve WHMCS Products into its respective Wordpress page. 

We want to keep the same web site pricing design, but to be dynamic with any product/update.

Also we would like to add an option to allow user to switch between currencies. 

Filtering products is required for example filter Server by Hard disk type (SSD, HDD), by processor type (AMD, Intel) or by  price range.

If you have a similar  already made code, please contact us for pricing.

Kind Regards

Mo

 

 

 

 

Link to comment
Share on other sites

  • 1 month later...

Yes, you can use a hook for this, with this hook you can export products with json using api;

<?php
use WHMCS\Database\Capsule;

add_hook('ClientAreaPage', 1, function ($vars) {
    if ($_GET['action'] === 'getProducts') {
        header('Content-Type: application/json');
        
        $products = Capsule::table('tblproducts')
            ->join('tblpricing', 'tblproducts.id', '=', 'tblpricing.relid')
            ->where('tblpricing.type', 'product')
            ->select('tblproducts.*', 'tblpricing.currency', 'tblpricing.msetupfee', 'tblpricing.monthly')
            ->get();
        
        echo json_encode($products);
        exit;
    }
});

This hook will return product information from WHMCS in JSON format when the /index.php?action=getProducts URL is accessed.
WordPress Side:

    Product Display with Shortcode: We show products dynamically by writing a shortcode in WordPress.

Shortcode Example:

function fetch_whmcs_products() {
    $response = wp_remote_get('https://your-whmcs-url.com/index.php?action=getProducts');
    if (is_wp_error($response)) {
        return 'Unable to retrieve products.';
    }
    
    $products = json_decode(wp_remote_retrieve_body($response), true);
    if (!$products) {
        return 'No products found.';
    }

    $output = '<div class="whmcs-products">';
    foreach ($products as $product) {
        $output .= '<div class="product">';
        $output .= '<h2>' . esc_html($product['name']) . '</h2>';
        $output .= '<p>' . esc_html($product['description']) . '</p>';
        $output .= '<p>Price: ' . esc_html($product['monthly']) . ' ' . esc_html($product['currency']) . '</p>';
        $output .= '</div>';
    }
    $output .= '</div>';

    return $output;
}
add_shortcode('whmcs_products', 'fetch_whmcs_products');

You can show products using [whmcs_products] shortcodes in WordPress content.

 

Update and improve the codes according to yourself, this is just an example.

Link to comment
Share on other sites

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