Я думаю, что вы имеете в виду это, не забывайте, что этот код на основе 1 категории для продукта , в противном случае вам придется настроить его дальше
ps может быть, вы должны рассмотреть этот метод? вместо перенаправления https://markjaquith.wordpress.com/2014/02/19/template_redirect-is-not-for-loading-templates/
function wc_custom_redirect_after_purchase() {
$product_categories1 = 'jobs';
$product_categories2 = 'courses';
$product_categories3 = 'exchange-post';
global $wp;
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
$cat_in_cart = false;
$order_id = isset( $wp->query_vars['order-received'] ) ? intval( $wp->query_vars['order-received'] ) : 0;
$order = new WC_Order( $order_id );
$product_categories = array( $product_categories1, $product_categories2, $product_categories3 );
foreach( $order->get_items() as $item ) {
$item_id = $item->get_product_id();
if( has_term( $product_categories, 'product_cat', $item_id ) ) {
$cat_in_cart = true;
$terms = get_the_terms( $item_id, 'product_cat' );
foreach ( $terms as $term ) {
// Categories by slug
$cat_name = $term->slug;
}
break;
}
}
if ( $cat_in_cart ) {
switch ($cat_name) {
case $product_categories1:
wp_redirect( 'https://steamroute.com/post-a-job-check-out/');
break;
case $product_categories2:
wp_redirect( 'https://steamroute.com/courses-checkout/');
break;
case $product_categories3:
wp_redirect( 'https://steamroute.com/exchange-checkout/');
break;
}
}
}
}
add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' );