In Woocommerce, I am working on my custom thank you page when you finish your order. Everything is done but what I need is to redirect english orders to english language Thank you page and major language to the major Thank you page.
I ve added this code to functions.php
but its only redirecting to the url which is set. How could I set 2 differend urls for 2 different languages?
Main language: Slovak
2nd language: English
Plugin used for translations: Polylang
My code:
add_action( 'template_redirect', 'woo_custom_redirect_after_purchase' );
function woo_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && !empty( $wp->query_vars['order-received'] ) )
{
wp_redirect( '/dakujeme-za-objednavku/' );
exit;
}
}
And when I use this code it redirects only to url which is not set to en_US (to /vi/cam-on not to thank you when the language is english
add_action( 'woocommerce_thankyou', 'bbloomer_redirectcustom');
function bbloomer_redirectcustom( $order_id ){
$order = new WC_Order( $order_id );
if( get_locale() == 'en_US'){
$url = get_site_url().'/thank-you';
}else{
$url = get_site_url().'/vi/cam-on';
}
if ( $order->status != 'failed' ) {
wp_redirect($url);
exit;
}
}