Skip to content

Instantly share code, notes, and snippets.

@finalwebsites
Created April 20, 2023 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finalwebsites/b3f412b820d8132efc3dce9575e2c5b1 to your computer and use it in GitHub Desktop.
Save finalwebsites/b3f412b820d8132efc3dce9575e2c5b1 to your computer and use it in GitHub Desktop.
WooCommerce: Redirect the customer to your own thank you page (one for successful payments and one for all other statuses)
<?php
add_action( 'woocommerce_thankyou', 'fw_redirect_custom_thank_you_page');
function fw_redirect_custom_thank_you_page( $order_id ){
$order = wc_get_order( $order_id );
$url = home_url('/YOUR_THANK_YOU_PAGE/'); // <<< change this slug
if ( $order->has_status( array('processing', 'completed' ) ) ) {
wp_safe_redirect( $url );
exit;
}
}
@finalwebsites
Copy link
Author

Place this code into the functions.php file from your WordPress child theme

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