{"id":2503,"date":"2019-12-22T15:01:31","date_gmt":"2019-12-22T15:01:31","guid":{"rendered":"https:\/\/ibex.tech\/wordpress-sites\/?p=2503"},"modified":"2022-02-17T07:15:07","modified_gmt":"2022-02-17T07:15:07","slug":"order-complete","status":"publish","type":"post","link":"https:\/\/ibex.tech\/wordpress-sites\/plugins\/woocommerce\/hooks-woocommerce\/order-complete","title":{"rendered":"Order complete"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Auto complete an order<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/******************************************************\n\/\/******************************************************\n\/\/********** AUTO COMPLETE WOOCOMMERCE ORDERS **********\n\/\/******************************************************\n\/\/******************************************************\nadd_action( 'woocommerce_thankyou', 'my_woocommerce_thankyou' );\nfunction my_woocommerce_thankyou( $order_id )\n{ \n  if (!$order_id)\n      return;\n\n  $order = wc_get_order($order_id);\n  \n  \/\/----- AUTO-COMPLETE THE ORDER -----\n  \/\/Don't auto complete for orders paid with Bank wire, Cash on delivery and Cheque payment methods\n  if (in_array($order->get_payment_method(), array( 'bacs', 'cod', 'cheque', '')))\n  {\n    return;\n  } \n  elseif($order->has_status('processing'))    \/\/For paid orders with all other payment methods auto complete the order\n  {\n    $order->update_status( 'completed' );\n  }\n  \n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Redirect on order completed<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/*********************************************************\n\/\/*********************************************************\n\/\/********** REDIRECT ON WOOCOMMERCE ORDER COMPLETE **********\n\/\/*********************************************************\n\/\/*********************************************************\nadd_action( 'woocommerce_thankyou', 'my_woocommerce_thankyou' );\nfunction my_woocommerce_thankyou( $order_id )\n{ \n  if (!$order_id)\n      return;\n\n  $order = wc_get_order($order_id);\n \n  \/\/----- REDIRECT ON ORDER COMPLETED -----\n  $url = 'https:\/\/yoursite.com\/custom-url';\n  if (!$order->has_status('failed'))\n  {\n    wp_safe_redirect( $url );\n    exit;\n  } \n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Auto complete an order Redirect on order completed<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[216,224],"tags":[],"class_list":["post-2503","post","type-post","status-publish","format-standard","hentry","category-hooks-woocommerce","category-orders"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/wordpress-sites\/wp-json\/wp\/v2\/posts\/2503","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/wordpress-sites\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/wordpress-sites\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/wordpress-sites\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/wordpress-sites\/wp-json\/wp\/v2\/comments?post=2503"}],"version-history":[{"count":4,"href":"https:\/\/ibex.tech\/wordpress-sites\/wp-json\/wp\/v2\/posts\/2503\/revisions"}],"predecessor-version":[{"id":2580,"href":"https:\/\/ibex.tech\/wordpress-sites\/wp-json\/wp\/v2\/posts\/2503\/revisions\/2580"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/wordpress-sites\/wp-json\/wp\/v2\/media?parent=2503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/wordpress-sites\/wp-json\/wp\/v2\/categories?post=2503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/wordpress-sites\/wp-json\/wp\/v2\/tags?post=2503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}