Grant S Posted July 29 Share Posted July 29 Hi all, I'm trying to display product pricing on my Wordpress website via WHMCS using data feeds, but because there's about 20 prices being displayed, it's incredibly slow. I've seen it mentioned that one should rather use hooks, but I'm really not sure how to implement this. Could someone please point me in the right direction? Thank you! 0 Quote Link to comment Share on other sites More sharing options...
Grant S Posted August 1 Author Share Posted August 1 Anyone? Am I missing something particularly obvious here? Should I somehow be dynamically pulling the pricing from a single file elsewhere? Thx 0 Quote Link to comment Share on other sites More sharing options...
1web Posted August 17 Share Posted August 17 On 8/1/2024 at 9:51 PM, Grant S said: Anyone? Am I missing something particularly obvious here? Should I somehow be dynamically pulling the pricing from a single file elsewhere? Thx UNTESTED Copy paste the below into an editor save it as whmcsdatafeed.php upload to your wordpress theme directory change the yourdomain.com/whmcs to the required domain details <?php // Set the cache file path and cache time (in seconds) $cache_file = 'whmcs_cache.json'; $cache_time = 3600; // 1 hour // Check if the cache file exists and is still valid if (file_exists($cache_file) && (time() - filemtime($cache_file) < $cache_time)) { // Read data from the cache file $data = json_decode(file_get_contents($cache_file), true); } else { // Fetch data from WHMCS $product_ids = [1, 2, 3]; // Add your product IDs here $data = []; foreach ($product_ids as $pid) { $description = file_get_contents("https://yourdomain.com/whmcs/feeds/productsinfo.php?pid=$pid&get=description"); $price = file_get_contents("https://yourdomain.com/whmcs/feeds/productsinfo.php?pid=$pid&get=price&billingcycle=monthly"); $data[] = ['description' => $description, 'price' => $price]; } // Save data to the cache file file_put_contents($cache_file, json_encode($data)); } // Output the data foreach ($data as $product) { echo '<div class="product">'; echo '<p>' . $product['description'] . '</p>'; echo '<p>Price: ' . $product['price'] . '</p>'; echo '</div>'; } ?> Add this to the page you want to show the data feeds on change file destination <?php include 'path/to/your/php/file.php'; ?> This script will fetch the product descriptions and pricing from WHMCS, cache the data for one hour, and display it on your WordPress site. This approach reduces the number of requests to WHMCS, speeding up the loading time 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted August 18 Share Posted August 18 (edited) Hooks are used for actions inside WHMCS ecosystem. Either use data feed (with better code for performance needs), either WHMCS external API. Edited August 18 by pRieStaKos 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.