如何在WooCommerce中使用自定义订单状态更改订单状态



您好,我有此代码,它将一个名为退款的自定义状态添加到订单状态

    function register_awaiting_shipment_order_status() {
    register_post_status( 'wc-awaiting-shipment', array(
        'label'                     => 'Return',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Return <span class="count">(%s)</span>', 'Return <span class="count">(%s)</span>' )
        ) );
        register_post_status( 'wc-refund-issued', array(
            'label'                     => 'Refund Issued',
            'public'                    => true,
            'exclude_from_search'       => false,
            'show_in_admin_all_list'    => true,
            'show_in_admin_status_list' => true,
            'label_count'               => _n_noop( 'Refund Issued<span class="count">(%s)</span>', 'Refund Issued <span class="count">(%s)</span>' )
            ) );
}
add_action( 'init', 'register_awaiting_shipment_order_status' );
// Add to list of WC Order statuses
function add_awaiting_shipment_to_order_statuses( $order_statuses ) {
    $new_order_statuses = array();
    // add new order status after processing
    foreach ( $order_statuses as $key => $status ) {
        $new_order_statuses[ $key ] = $status;
        if ( 'wc-processing' === $key ) {
            $new_order_statuses['wc-awaiting-shipment'] = 'Return';
            $new_order_statuses['wc-refund-issued'] = 'Refund Issued';
        }
    }
    return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_awaiting_shipment_to_order_statuses' );

我希望能够通过以下方式更改自定义订单状态

$order->status_update('refund issued');

但它不起作用,它仅适用于 wooCommerce 已经附带的状态,例如处理和待付款,当我运行代码时,它将状态更改为待付款而不是退款发放我做错了什么? 最后,IM试图完成的是"查看订单"区域中的退款按钮,以便用户可以向当前订单发出退款请求。

问题解决了,我说它错了,应该是

$order->status_update('wc-refund-issued');  

而不是

$order->status_update('refund issued');

谢谢

相关内容

  • 没有找到相关文章

最新更新