【问题标题】:Auto change order status from hold-on to processing in Woocommerce在 Woocommerce 中自动将订单状态从等待更改为处理
【发布时间】:2018-08-01 16:33:40
【问题描述】:

我想更改 每个 订单 来自 woocommerce 状态为'HOLD-ON ' 到'PROCESSING' 用php

我已经尝试在functions.php 文件中编写一个函数,但我失败了。

如何在 Woocommerce 中自动将订单状态从“等待”更改为“处理中”?

【问题讨论】:

    标签: php wordpress woocommerce status orders


    【解决方案1】:

    将代码添加到您的子主题的 functions.php 文件或通过允许添加自定义函数的插件,例如 Code sn-ps 插件。避免将自定义代码直接添加到父主题的 functions.php 文件中,因为当您更新主题时,这将被完全清除。

    您还可以将“已完成”状态更改为另一个订单状态,例如“处理中”

       **
    * Auto Complete all WooCommerce orders.
    */
    add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
    function custom_woocommerce_auto_complete_order( $order_id ) { 
       if ( ! $order_id ) {
           return;
       }
    
       $order = wc_get_order( $order_id );
       $order->update_status( 'processing' );
    } ```
    

    【讨论】:

      【解决方案2】:
      add_action('woocommerce_order_status_changed', 'ts_auto_complete_by_payment_method');
      
      function ts_auto_complete_by_payment_method($order_id)
      {
      
      if ( ! $order_id ) {
      return;
      }
      
      global $product;
      $order = wc_get_order( $order_id );
      
      if ($order->data['status'] == 'on-hold') {
      $payment_method=$order->get_payment_method();
      if ($payment_method!="COD")  // change payment method 
      {
      $order->update_status( 'processing' );
      }}}
      

      【讨论】:

      • 请不要只发布代码作为答案,还要解释您的代码的作用以及它如何解决问题的问题。带有解释的答案通常更有帮助,质量更高,更有可能吸引投票。
      【解决方案3】:

      要自动处理订单,您应该尝试以下操作:

      add_action( 'woocommerce_thankyou', 'woocommerce_auto_processing_orders');
      function woocommerce_auto_processing_orders( $order_id ) {
          if ( ! $order_id )
              return;
      
          $order = wc_get_order( $order_id );
      
          // If order is "on-hold" update status to "processing"
          if( $order->has_status( 'on-hold' ) ) {
              $order->update_status( 'processing' );
          }
      }
      

      代码进入活动子主题(或主题)的 function.php 文件中。

      【讨论】:

        猜你喜欢
        • 2022-10-14
        • 2019-06-01
        • 2023-01-28
        • 2016-08-04
        • 2018-02-27
        • 2018-02-09
        • 2019-02-21
        • 2020-08-11
        • 2017-05-24
        相关资源
        最近更新 更多