Auto complete an order

//******************************************************
//******************************************************
//********** AUTO COMPLETE WOOCOMMERCE ORDERS **********
//******************************************************
//******************************************************
add_action( 'woocommerce_thankyou', 'my_woocommerce_thankyou' );
function my_woocommerce_thankyou( $order_id )
{ 
  if (!$order_id)
      return;

  $order = wc_get_order($order_id);
  
  //----- AUTO-COMPLETE THE ORDER -----
  //Don't auto complete for orders paid with Bank wire, Cash on delivery and Cheque payment methods
  if (in_array($order->get_payment_method(), array( 'bacs', 'cod', 'cheque', '')))
  {
    return;
  } 
  elseif($order->has_status('processing'))    //For paid orders with all other payment methods auto complete the order
  {
    $order->update_status( 'completed' );
  }
  
}

Redirect on order completed

//*********************************************************
//*********************************************************
//********** REDIRECT ON WOOCOMMERCE ORDER COMPLETE **********
//*********************************************************
//*********************************************************
add_action( 'woocommerce_thankyou', 'my_woocommerce_thankyou' );
function my_woocommerce_thankyou( $order_id )
{ 
  if (!$order_id)
      return;

  $order = wc_get_order($order_id);
 
  //----- REDIRECT ON ORDER COMPLETED -----
  $url = 'https://yoursite.com/custom-url';
  if (!$order->has_status('failed'))
  {
    wp_safe_redirect( $url );
    exit;
  } 
}
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published.