I'm trying to fetch the last order from my Shopify store through the Shopify API on Wordpress with PHP.
我正試圖通過使用PHP的Wordpress上的Shopify API從Shopify商店獲取最后一個訂單。
The PHP documentation for Shopify API is pretty limited so I'm having some trouble actually getting the data, any data, to be echoed into my Wordpress page.
Shopify API的PHP文檔非常有限,因此我在實際獲取數據時遇到一些麻煩,任何數據都會回顯到我的Wordpress頁面。
I've made my Private App on Shopify and I'm using its credentials in the code below (replaced with brackets for security purposes). The app has read access to everything within the shop. There are recent orders, so that is not the problem.
我在Shopify上制作了我的私人應用程序,並且我在下面的代碼中使用了它的憑據(出於安全目的替換為括號)。該應用程序可以讀取商店內的所有內容。最近訂單,所以這不是問題。
Here is the code that I'm using to display within the body of my Wordpress page:
這是我用於在Wordpress頁面正文中顯示的代碼:
$orders_obj_url = 'https://[my api key]:[my api secret]@[my shopify URL handle].myshopify.com/admin/orders.json';
$orders_content = @file_get_contents( $orders_obj_url );
$orders_json = json_decode( $orders_content, true );
$orders = $orders_json['orders'];
echo $orders;
?>
The code above is simply attempting to get the raw array to be outputted onto my page. It currently outputs nothing.
上面的代碼只是試圖將原始數組輸出到我的頁面上。它目前沒有任何輸出。
Past this, I'd like to get the most recent order object in the JSON array and only output that one.
在此之前,我想在JSON數組中獲取最新的訂單對象,並僅輸出該訂單。
There's probably a painfully obvious error in my code or implementation, I've just been staring at it too long and need a fresh pair of eyes. Thanks.
在我的代碼或實現中可能存在一個非常明顯的錯誤,我只是盯着它看了太長時間,需要一雙新鮮的眼睛。謝謝。
1 个解决方案
#1
0
First you will get all order list from shopify order api (GET /admin/orders.json).
all order get in array list so get last array from array list and get order id from las t array.then this order id use for get data of last order id and use this api for get specific order data (api for get specific order data :GET /admin/orders/#{order_id}.json)