gpt4 book ai didi

php - woocommerce 自定义订单状态和 REST API

转载 作者:行者123 更新时间:2023-12-05 07:21:32 25 4
gpt4 key购买 nike

我在 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';

关于php - woocommerce 自定义订单状态和 REST API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56852099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com