我想通过API在Woocommerce上更新4条数据。我一直在如下使用它们,没有问题,但想介绍一些错误检查,也可以使用Promise。在这种情况下,我应该使用回调,promise还是async / await吗?
第一个添加订单注释,第二个功能设置订单状态:
// Update Woocommerce Orders
var WooCommerce = new WooCommerceAPI({
url: process.env.WOOAPI_URL, // Your store URL
consumerKey: process.env.WOOAPI_KEY, // Your consumer key
consumerSecret: process.env.WOOAPI_SECRET, // Your consumer secret
wpAPI: true, // Enable the WP REST API integration
version: 'wc/v3' // WooCommerce WP REST API version
});
var data = {
note: 'Order is complete'
};
WooCommerce.post('orders/' + orderId + '/notes', data, function (err, data, res) {
if (err) throw err;
console.log(res);
});
var status = {
status: 'completed'
};
WooCommerce.post('orders/' + orderId, status, function (err, states, res) {
if (err) throw err;
console.log(res);