shopify api php 开发,Shopify API獲取PHP的最后一個訂單

在WordPress上尝试使用PHP的Shopify API获取Shopify商店的最后一个订单时遇到问题。已创建私有应用并具有读取权限,但无法从API获取数据。代码尝试获取订单数组并输出,但没有结果。解决方案是首先通过GET /admin/orders.json API获取所有订单列表,然后从列表中获取最后一个订单ID,再使用该ID通过GET /admin/orders/#{order_id}.json获取特定订单详情。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值