Last active
June 13, 2024 23:36
-
-
Save Acephalia/cf80e9a154cb6989590518040371c79e to your computer and use it in GitHub Desktop.
WooCommerce Redirect Thank You Page Based On Order Status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For reddit request : https://www.reddit.com/r/woocommerce/comments/1dewo3o/hosted_payment_page/
Caffeinate me: https://buymeacoffee.com/acephaliax
Order Statuses in WooCommerce: