Thank you page redirect coding function.php child theme
-
Hi everyone i just used this code yesterday for redirect to a custom thank you page for specific product category:
// Redirigir a una página diferente si compra un producto de la categoría ‘mezcla-y-mastering-online’
add_action( ‘template_redirect’, ‘wc_custom_redirect_after_purchase’ );
function wc_custom_redirect_after_purchase() {
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( ‘mezcla-y-mastering-online’ );foreach( $order->get_items() as $item ){
if( has_term( $product_categories, ‘product_cat’, $item->get_product_id() ) ) {
$cat_in_cart = true;
break;
}
}if ( $cat_in_cart ) {
wp_redirect( ‘https://artchitectsproductions.com/gracias-compra-mezcla-y-mastering-online/’);
} else {
wp_redirect( ‘https://artchitectsproductions.com/gracias-por-tu-compra/’);
}
exit;}
}
Contract
Everything works so well but now i want to add one more category to redirect and i don’t know wich code should i use to have two specific categories custom redirects.I use everything inside child theme.
Thanks a lot!
- The topic ‘Thank you page redirect coding function.php child theme’ is closed to new replies.