corsonr
2/26/2015 - 2:21 PM

Redirect thank you page by product SKU

Redirect thank you page by product SKU

<?php
add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' );

function wc_custom_redirect_after_purchase() {
    global $wp, $product, $woocommerce;
    
    $product_sku = $_product->parent->sku;

    if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
	    switch ($product_sku) {
	    	case 'aaa':
	    		wp_redirect( 'http://www.yoururl.com/your-page-aaa/' );
	    		break;
	    	case 'bbb':
	    		wp_redirect( 'http://www.yoururl.com/your-page-bbb/' );
	    		break;
	    	case 'ccc':
	    		wp_redirect( 'http://www.yoururl.com/your-page-ccc/' );
	    		break;
	    	
	    }
        exit;
    }
}