search

Home  >  Q&A  >  body text

Keep Woocommerce order status as pending

I don't want Woocommerce to automatically update the order status from "Paused" to "Completed". I would like it to remain "on hold" as we are sending replacement items and waiting for the original items to be returned to us. Basically, I want to set it to "on hold" even after the item has been shipped. Is there any way to achieve this?

I tried using the following code without success:

add_action( 'woocommerce_payment_complete', 'cancel_completed_status' );
   
function cancel_completed_status( $order_id ){
  $order = wc_get_order( $order_id );
  $items = $order->get_items(); 
  foreach ( $items as $item_id => $item ) {
    $product_id = $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id();
    
    if ( $order->has_status( 'on-hold' )) {
        $order->update_status( 'on-hold' );
        $order->save();
    }
  }
}

P粉627136450P粉627136450248 days ago513

reply all(1)I'll reply

  • P粉476547076

    P粉4765470762024-03-29 10:54:28

    add_action('woocommerce_order_status_completed', 'completed_to_onhold');
    
    function completed_to_onhold($order_id) {
    
        $order = new WC_Order($order_id);
        $order->update_status('on-hold');
    }

    reply
    0
  • Cancelreply