duanke2503 2019-04-05 08:14
浏览 237

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

Hello i have this code which adds a custom status called refund issued to the order status

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

i want to be able to change the custom order status through

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

but it doens't work it only work for the status that already comes with woocommerce like processing and pending payment when i run the code it changes the status to payment pending instead of refund issued what am i doing wrong ? in the end what im trying to accomplish is to make a refund button in the view order area so the user can issue a refund request to the current order

  • 写回答

1条回答 默认 最新

  • drhs13583567608 2019-04-05 08:26
    关注

    Problem solved i was calling it wrong it supposed to be

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

    instead of

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

    Thank you very much

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题