简体   繁体   中英

woocommerce custom Order Status and REST API

I added a custom order status to woocommerce with php in function.php.

I can see/set this status on the admin surface, but I would like to use REST API (v2 or v3) and update orders to this set this new status.

API returns this error : Error: In: status [rest_invalid_param]

I can set pre-built status for orders but not the new one. How can I do this?

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 );

Don't use "wc-" in front of the custom order status.

Ie in WooCommerce I have created an order status called "wc-new-quote". Now the REST API gives me an error when I try to post:

$data['status'] = 'wc-new-quote';

The correct way is:

$data['status'] = 'new-quote';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM