Change Status of WooCommerce Paypal Order from Processing to Complete

Using WooCommerce and Paypal, sometimes you may want the order to go from processing to complete on payment of the order at Paypal without manually having to set it to complete, this snippet as provided by WooCommerce fixes this issue.

/**
 * Auto Complete all WooCommerce orders.
 * Add to theme functions.php file
 */
 
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
 global $woocommerce;
 
 if ( !$order_id )
  return;
 $order = new WC_Order( $order_id );
 $order->update_status( 'completed' );
}

Add this to your functions.php theme file.