donglu9872 2019-02-27 05:21
浏览 68

将后端创建的预订订单更改为WooCommerce中的自定义状态

When creating an order with a booking in backend, the order status is set to pending, but I want the booking order created to be set to a custom order status that uses service-booked as slug, on order creation.

How can I change backend created booking orders to a custom status in WooCommerce?

  • 写回答

2条回答 默认 最新

  • dougou6727 2019-02-27 06:01
    关注
    add_action( 'init', 'register_my_new_order_statuses' );
    
    function register_my_new_order_statuses() {
        register_post_status( 'wc-service-booked', array(
            'label'                     => _x( 'Service Booked', 'Order status', 'woocommerce' ),
            'public'                    => true,
            'exclude_from_search'       => false,
            'show_in_admin_all_list'    => true,
            'show_in_admin_status_list' => true,
            'label_count'               => _n_noop( 'Service Booked <span class="count">(%s)</span>', 'Service Booked<span class="count">(%s)</span>', 'woocommerce' )
        ) );
    }
    
    add_filter( 'wc_order_statuses', 'my_new_wc_order_statuses' );
    
    // Register in wc_order_statuses.
    function my_new_wc_order_statuses( $order_statuses ) {
        $order_statuses['wc-service-booked'] = _x( 'Service Booked', 'Order status', 'woocommerce' );
    
        return $order_statuses;
    }
    
    add_action( 'woocommerce_order_status_pending', 'mysite_processing');
    add_action( 'woocommerce_order_status_processing', 'mysite_processing');
    
    function mysite_processing($order_id){
         $order = wc_get_order( $order_id );
    
         if ( ! $order ) {
            return;
         }
    
         // Here you can check the product type in the order is your booking                     
         //   product and process accordingly
         // update status to service booked
         $order->update_status('service-booked'); 
    
    }
    

    Tested OK with WooCommerce 3.5.5 and WordPress 5.1

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大