WooCommerce Redirect After Checkout
Building better MyListing websites. One code snippet at a time.
Overview
The WooCommerce Redirect After Checkout code snippet allows for greater flexibility within a MyListing website.
This snippet is commonly used when website owners want to show customers a welcome page after checkout. Welcome pages are great ways to educate customers, upsell them, and more.
Implementation
- Grab the code snippet.
- Follow the provided instructions.
- Save your changes.
//// INSTRUCTIONS:
//// Copy and paste the code snippet below into the child theme's functions.php file.
//// You can edit the functions.php file from your WordPress dashboard (Appearance > Theme Editor) or via FTP.
//// NOTES:
//// The WooCommerce Redirect After Checkout code snippet allows for greater flexibility within a MyListing website.
//// This snippet is commonly used when website owners want to show customers a welcome page after checkout.
//// Welcome pages are great ways to educate customers, upsell them, and more.
--------------------------- CODE SNIPPET IS BELOW THIS LINE ---------------------------
// WOOCOMMERCE REDIRECT AFTER CHECKOUT
add_action( 'woocommerce_welcome', 'mlclub_redirectcustom');
function mlclub_redirectcustom( $order_id ){
$order = wc_get_order( $order_id );
$url = 'https://yoursite.com/custom-url';
if ( ! $order->has_status( 'failed' ) ) {
wp_safe_redirect( $url );
exit;
}
}