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

问题描述 投票:0回答:1

您好我有这个代码,它会在订单状态中添加一个名为退款的自定义状态

    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状态,如处理和待付款,当我运行代码,它将状态更改为付款待定,而不是退款发出我做错了什么?最后,我想要完成的是在视图订单区域中设置退款按钮,以便用户可以向当前订单发出退款请求

php wordpress methods woocommerce orders
1个回答
0
投票

问题解决了,我认为它错了

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

代替

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

非常感谢你

© www.soinside.com 2019 - 2024. All rights reserved.