widiman Posted December 15, 2024 Share Posted December 15, 2024 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 0 Quote Link to comment Share on other sites More sharing options...
Slaweally Posted 21 hours ago Share Posted 21 hours ago 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. 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.