简体   繁体   English

根据订单备注更改 Woocommerce 订单状态

[英]Changing Woocommerce Order Status based on order notes

I've been looking around to find a way to change our woocommerce orders status based on the order notes.我一直在寻找一种方法来根据订单备注更改我们的 woocommerce 订单状态。 We have a card processor that adds order notes when an order is approved, but it puts the order on hold because the card is only authorized not charged.我们有一个卡处理器,它会在订单获得批准时添加订单备注,但它会暂停订单,因为卡只被授权而不被收费。 We charge the card later once the order has been shipped, but we need the order to go into "processing" so we can export the order into our system so we can actually process the order (we don't process through woocommerce).一旦订单发货,我们稍后会向卡收费,但我们需要将 go 的订单进行“处理”,以便我们可以将订单导出到我们的系统中,以便我们可以实际处理订单(我们不通过 woocommerce 处理)。

I found this code however, I'm wondering if this can be modified to pull what is in the order notes since our processor adds whether or not the card has been approved.但是我找到了这段代码,我想知道是否可以修改它以提取订单说明中的内容,因为我们的处理器添加了卡是否已被批准。

function mysite_woocommerce_payment_complete( $order_id ) {
    error_log( "Payment has been received for order $order_id" );
}
add_action( 'woocommerce_payment_complete', 'mysite_woocommerce_payment_complete', 10, 1 );

Here is a Example which switch on hold order status with processing.这是一个通过处理打开暂停订单状态的示例。 you can use it or if need to add some more condition, please mention here or update it accordingly.您可以使用它,或者如果需要添加更多条件,请在此处提及或相应更新。 Thanks谢谢

function switch_hold_status_to_processing ($order_id) {
  $order = new WC_Order( $order_id );
  $order->update_status('processing');
}
add_action('woocommerce_order_status_on-hold', 'switch_hold_status_to_processing');

You can use wc_get_order_notes($args) function to get the order notes in the specific order.您可以使用wc_get_order_notes($args) function 来获取特定订单的订单备注。 It returns an array of order notes.它返回一个订单注释数组。 Then you can loop through the array to find the order note you need.然后您可以遍历数组以找到您需要的订单注释。 Then use an if statement to verify the content of the order note and update the status.然后使用if语句来验证订单备注的内容并更新状态。

function mysite_woocommerce_payment_complete( $order_id ) {
    $order_notes = wc_get_order_notes([
        'order_id' => $order_id,
     ]);
    foreach ($order_notes as $order_note){
        if ($order_note->content == "Order verified"){
            $order = new WC_Order( $order_id );
            $order->update_status('processing');
            break;
        }
    }
    
}
add_action( 'woocommerce_payment_complete', 'mysite_woocommerce_payment_complete', 10, 1 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM