这肯定会显示所有订单
enter code here
const WooCommerceRestApi = require("@woocommerce/woocommerce-rest-api").default;
const api = new WooCommerceRestApi({
url: process.env.NEXT_PUBLIC_WORDPRESS_SITE_URL,
consumerKey: process.env.CONSUMER_KEY,
consumerSecret: process.env.CONSUMER_SECRET,
version: "wc/v3"
});
export default async function handler(req, res){
const responseData = {
success:false,
orders: []
}
const { perPage} = req?.query ?? {};
try {
const {data} = await api.get(
\'orders\',
{
per_page:perPage||100
}
);
responseData.success = true;
responseData.orders = data;
res.json( responseData);
} catch ( error ){
responseData.error = error.message;
res.status(500).json(responseData);
}
}