Skip to content

Instantly share code, notes, and snippets.

@Acephalia
Last active April 4, 2023 05:48
Show Gist options
  • Save Acephalia/8dd50d8129efa3df5ae3dd6447f87de2 to your computer and use it in GitHub Desktop.
Save Acephalia/8dd50d8129efa3df5ae3dd6447f87de2 to your computer and use it in GitHub Desktop.
Redirect to Seperate Thank You Page For 2 or More Items
Use snippet wcrtpf2omi2.php if you don't want the snippet to handle redirection for single products. Replace the $thankyou_page_url and $thankyou_multiple_page_url variables with the URLs of your custom thank you pages as needed.
function custom_thankyou_redirection() {
global $woocommerce;
$items_count = $woocommerce->cart->cart_contents_count;
$thankyou_page_url = 'https://www.yourwebsite.com/thank-you/';
$thankyou_multiple_page_url = 'https://www.yourwebsite.com/thank-you-multiple/';
if ( $items_count >= 2 ) {
wp_redirect( $thankyou_multiple_page_url );
exit;
} else {
wp_redirect( $thankyou_page_url );
exit;
}
}
add_action( 'woocommerce_thankyou', 'custom_thankyou_redirection' );
function custom_thankyou_redirection() {
global $woocommerce;
$items_count = $woocommerce->cart->cart_contents_count;
if ( $items_count >= 2 ) {
$thankyou_multiple_page_url = 'https://www.yourwebsite.com/thank-you-multiple/';
wp_redirect( $thankyou_multiple_page_url );
exit;
}
}
add_action( 'woocommerce_thankyou', 'custom_thankyou_redirection' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment