I used a code to redirect the buyer to a customised page. But I would like to add a different redirect per product category as set in Woocommerce.
This is the code I’m using to redirect for all purchases. Now I need to change it to a redirect per categegory. For example if someone buys a shop product it goed to page A and when they purchase a course it goes to page B after purchase.
<?php
/* Redirect user after check out */
add_action( 'template_redirect', 'jay_custom_redirect_after_purchase' );
function jay_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
wp_redirect( 'http://www.yoururl.com/your-page/' );
exit;
}
}
2
Answers
In my suggestion I changed the action you selected to allow get order id. So with this informations I obtained the order items and its categories.
You can use the
woocommerce_thankyou
hook.If the order contains a product from a certain category, it redirects to the corresponding product category page.
The code must be added to the functions.php of your active theme.