【问题标题】:woocommerce booking status changes woocommerce order statuswoocommerce 预订状态更改 woocommerce 订单状态
【发布时间】:2017-05-24 01:04:25
【问题描述】:

我正在使用 woocommerce 预订。 如果woocommerce_booking 状态被取消,我正在尝试触发 woocommerce 订单状态退款。我试过这段代码,但它不起作用。

global $woocommerce;
$order = new WC_Order( $order_id );
if ( 'cancelled' == $order->status ) {
   $order->update_status('refund', 'order_note');
}

【问题讨论】:

  • 什么不起作用?你检查过 $order->status 吗?
  • 是的,我检查了订单状态。它保持不变。它应该更改为退款,但它不起作用。
  • spreek jij toevallig Nederlands Jeroen? Ik zit al weken 遇到了 hetzelfde 问题。 Komt het omdat de order wordt geplaatst via een booking? (woocommerce 预订)
  • 是的,我住在荷兰。我不是真正的专家,但在 Google 上查看并发现 this SO question 和 this 文章建议您的代码应该可以工作。您可以通过更改为其他状态来测试这一点。 docs 表示退款仅在您的“支付网关支持”时才有效。首先手动尝试并使用找到的结果更新您的问题。
  • 似乎没有人理解我的问题。我需要 woocommerce 预订状态(已取消)将 woocommerce 订单状态更改为退款。

标签: wordpress woocommerce hook-woocommerce


【解决方案1】:

在取消状态时更新订单状态

add_action('woocommerce_cancelled_order','change_status_to_refund', 10, 1);
 function change_status_to_refund($order_id) {
    $order = new WC_Order( $order_id );
    $order->update_status('refund', 'order_note');
    exit;
 }

希望对你有所帮助。谢谢:)

【讨论】:

    【解决方案2】:
    add_action( 'woocommerce_order_status_changed', 'wc_order_status_changed', 99, 3 );
    
    function wc_order_status_changed( $order_id, $old_status, $new_status ){
        if( $new_status == "cancelled" ||  $new_status == "refunded" ) {
            //code here.
        }
    }
    

    如果你想在一些集体行动中使用必须是这样的:

    add_action( 'woocommerce_order_status_changed', array($this, 'wc_order_status_changed'), 99, 3 );
    

    【讨论】:

      【解决方案3】:

      您需要获取订单状态,然后检查您所需的条件并相应更新。

      $order_status = $order->get_status();
      

      【讨论】:

        【解决方案4】:

        我知道这是一篇旧帖子,但我刚刚在我最新的 wordpress/woocommerce 安装中成功了

        add_action('woocommerce_booking_cancelled', 'my_booking_cancelled_handler', 10, 1);
        function my_booking_cancelled_handler ( $booking_id ) {
          $booking = new WC_Booking( $booking_id );
          $order_id = $booking->get_order_id();
          // check order for your business logic
          // refund or not ;-) it's up to you
        }
        

        我希望这对某人有所帮助。

        【讨论】:

          【解决方案5】:
          //Try this
          
          
          add_action( 'woocommerce_order_status_changed', 'auto_destroy_failed_orders', 10, 4 );
          
          function auto_destroy_failed_orders( $order_id, $old_status, $new_status, $order )
           {
              if ( ( $new_status == 'completed' )) {
                  // Order status complete 
                  $order->update_status( 'custom-status' );
          
              }else if ( ( $new_status == 'failed' )) {
                  $order->update_status( 'custom-status' );
          
              }else if ( ( $new_status == 'b2c-shipment' )) {
                  // custome status
                  $order->update_status( 'custom-status' );
          
              }else if ( ( $new_status == 'on-hold' )) {
                  // Order status to on-hold
                  $order->update_status( 'custom-status' );
          
              }else if ( ( $new_status == 'refunded' )) {
                  // Order status to refunded
                  $order->update_status( 'custom-status' );
          
              }else if ( ( $new_status == 'failed' )) {
                  // Order status to failed
                  $order->update_status( 'custom-status' );
          
              }else if ( ( $new_status == 'processing' ) ) {
                  // Order status to processing
                  $order->update_status( 'custom-status' );
              } 
          }
          

          【讨论】:

            【解决方案6】:

            嘿,你可以试试这个钩子!!

            https://therichpost.com/change-product-order-status-woocommerce-hook
            

            希望对你有帮助

            【讨论】:

              猜你喜欢
              • 2018-08-30
              • 2022-10-05
              • 2018-01-01
              • 2019-02-01
              • 2022-09-30
              • 2021-04-08
              • 2016-08-04
              • 1970-01-01
              • 2017-07-16
              相关资源
              最近更新 更多