WHMCS模版直接掉调用产品数据

function可以丢header.tpl里面

{php}
function getProducts($gid) {
    // 定义要发送的请求数据
    $postData = array('gid' => $gid);
    // 发送请求并获取结果
    $results = localAPI('GetProducts', $postData, 'admin');
    // 初始化一个数组,用于存储产品信息
    $products = array();
    // 遍历结果,提取所需信息并存储到数组中
    foreach ($results['products']['product'] as $product) {
        $description = $product['description'];
        $products[] = array(
            'stockcontrol' =>  $product['stockcontrol'],
            'stocklevel' => $product['stocklevel'],
            'name' => $product['name'],
            'url' => $product['product_url'],
            'pid' => $product['pid'],
            'desc' => $description,
            'prefix' => $product['pricing']['USD']['prefix'],
            'price' => $product['pricing']['USD']['monthly'],
            'yprice' => $product['pricing']['USD']['annually'],
        );
    }
    // 返回产品信息数组
    return $products;
}

// 调用函数获取产品信息,并传递变量gid作为参数
$getProducts= getProducts("1");
$_smarty_tpl->assign('getProducts', $getProducts);
{/php}

{foreach $Getproduct as $value }
                                <tr>
                                {$value.desc}
                                    <td><span class="price">{$value.prefix}{$value.price}<span>/MRC</span></span> </td>
                                    <td>
{if  isset($value.stocklevel)  &&   $value.stocklevel < 1  }
                                        <button type="button" class="btn btn-warning">Sold Out</button>
{else}
                                        <a href="/cart.php?a=add&pid={$value.pid}" class="btn btn-success">Order</a>
{/if}
                                    </td>
</tr>
{/foreach}

添加新评论 »