php - woocommerce 自定义订单状态和 REST API
问题描述
我在 function.php 中使用 php 向 woocommerce 添加了自定义订单状态。
我可以在管理界面上查看/设置此状态,但我想使用 REST API(v2 或 v3)并将订单更新为设置此新状态。
API 返回此错误:错误:在:状态 [rest_invalid_param]
我可以为订单设置预建状态,但不能为新订单设置。我怎样才能做到这一点?
WordPress 5.2.2,WooCommerce 3.6.4
function wpblog_wc_register_post_statuses() {
register_post_status( 'wc-invoicing', array(
'label' => 'XXXX',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'XXXX <span class="count">
(%s)</span>', 'XXXX alatt <span class="count">(%s)</span>' )
));
}
add_filter( 'init', 'wpblog_wc_register_post_statuses' );
function wpblog_wc_add_order_statuses( $order_statuses ) {
$order_statuses['wc-invoicing'] =
_x( 'XXXX alatt', 'Order Status', '' );
return $order_statuses;
}
add_filter( 'wc_order_statuses', 'wpblog_wc_add_order_statuses', 10, 1 );
解决方案
不要在自定义订单状态前使用“wc-”。
即在 WooCommerce 中,我创建了一个名为“wc-new-quote”的订单状态。现在,当我尝试发布时,REST API 给了我一个错误:
$data['status'] = 'wc-new-quote';
正确的方法是:
$data['status'] = 'new-quote';
推荐阅读
- javascript - 如果可用,我可以从微距相机创建流吗?
- javascript - 如何使用反应查询在按钮单击时调用相关 API?
- java - Java EventEmitter客户端重新连接不起作用
- php - 在 Woocommerce 中显示和设置含税和不含税的价格
- node-red - 在不同的 JSON 对象中合并超过 3 个 csv 文件 node-red
- javascript - 如何使 JavaScript 中添加的元素像 HTML 中添加的元素一样响应 onclick?
- java - 返回 MaterialTimePicker
- docker - 构建图像返回 SSL 连接无法建立,请参阅内部异常
- reactjs - 在生产模式下,反应头盔异步不起作用,反应头盔异步如何工作?
- cairo - 如何通过 Image Magick 在 Cairo Graphics 中包含图像?