Skip to content

Instantly share code, notes, and snippets.

@Acephalia
Last active June 13, 2024 23:36
Show Gist options
  • Save Acephalia/cf80e9a154cb6989590518040371c79e to your computer and use it in GitHub Desktop.
Save Acephalia/cf80e9a154cb6989590518040371c79e to your computer and use it in GitHub Desktop.
WooCommerce Redirect Thank You Page Based On Order Status
/*
* @snippet WooCommerce Redirect Thank You Page Based On Order Status
* @description This snippet will redirect a user to a seperate page depending on created order status.
* @author u/acephaliax
* @source. https://gist.github.com/Acephalia/cf80e9a154cb6989590518040371c79e
* @compatiblity Last tested on WooCommerce 8.9.2
* @community r/wordpress, r/woocommerce
* @caffeinate https://buymeacoffee.com/acephaliax
*/
add_action( 'woocommerce_thankyou', 'insomniainc_wallet_woes' );
function insomniainc_wallet_woes( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
if ( ! $order ) {
return;
}
// Change target status and url here
if ( $order->get_status() === 'pending' ) {
wp_redirect( home_url( '/failed' ) );
exit;
}
}
@Acephalia
Copy link
Author

Acephalia commented Jun 13, 2024

For reddit request : https://www.reddit.com/r/woocommerce/comments/1dewo3o/hosted_payment_page/
Caffeinate me: https://buymeacoffee.com/acephaliax

Order Statuses in WooCommerce:

  • Pending: Order received, awaiting payment.
  • Processing: Payment received and the stock has been reduced; the order is awaiting fulfillment.
  • On hold: Awaiting payment – stock is reduced but the order needs confirmation.
  • Completed: Order fulfilled and complete – no further action is required.
  • Cancelled: Cancelled by an admin or the customer – no further action is required.
  • Refunded: Refunded by an admin – no further action is required.
  • Failed: Payment failed or was declined (unpaid).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment