Woocommerce Rest API与自定义php仪表板集成

时间:2018-09-17 18:51:51

标签: php api woocommerce woocommerce-rest-api

<?php

require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;

$woocommerce = new Client(
    'https://shopurl',
    'ck_************************',
    'cs_**********************',
    [
        'wp_api' => true,
        'version' => 'wc/v2',
        'query_string_auth' => true // Force Basic Authentication as query string true and using under HTTPS
    ]
);

try {   
    $results = $woocommerce->get('orders');
    $products = $woocommerce->get('products');
    $customers = $woocommerce->get('customers');
    $result = $count($results);
    $customer = count($customers);
    $product = count($products);
}
catch(HttpClientException $e) {
    $e->getMessage(); // Error message.
    $e->getRequest(); // Last request data.
    $e->getResponse(); // Last response data.
}

当我使用<?php echo $result?>时,网站显示我有5个订单,因此api正在工作。

我想显示订单详细信息,我使用以下代码:

<?php
foreach( $results as $details ) {
    echo $details["status"];
    echo $details["created_at"];
    echo $details["currency"];
    echo $details["total"];
}
?>

但是api不显示任何内容。我该如何解决?有任何想法吗?

0 个答案:

没有答案