Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
I want to redirect pages based on the language.
E.g:
'en' => http://my-site.com/thankyou
'ar' => http://my-site.com/ar/thankyou

Solution:
For this purpose, you can use this hook https://wpml.org/wpml-hook/wpml_current_language/

Example:

        $my_current_lang = apply_filters( 'wpml_current_language', NULL );
        if ( 'ar' == $my_current_lang ) {
                wp_redirect( 'http://my-site.com/ar/thankyou' );
        }
         
        if ( 'en' == $my_current_lang ) {
                wp_redirect( 'http://my-site.com/thankyou' );
        }

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 4 replies, has 2 voices.

Last updated by attiahA 5 years ago.

Assigned support staff: Dat Hoang.

Author Posts
June 21, 2016 at 2:59 am #921238

attiahA

Hello
i want your help to convert this link to multi language support
i use arabic and english

// thankyou page Start
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'] ) ) {
		wp_redirect( '<em><u>hidden link</u></em>' );
		exit;
	}
}
// thankyou page End

i have

hidden link
hidden link

Thanks

June 21, 2016 at 9:42 am #921627

Dat Hoang

#1,
Can you please explain more about the situation you're using this?
In general, you can use this hook to get the current language https://wpml.org/wpml-hook/wpml_current_language/ then redirect to anywhere you want.

Does that help?

#2, Add this info if #1 does not help.

Please go to WPML > Support > Debug Information and give me the information in the next reply. You can read the detailed instruction here: http://wpml.org/faq/provide-debug-information-faster-support/

June 21, 2016 at 2:28 pm #922684

attiahA

this is for thankyo page to woocommerce

i want from you the current code with multi language support

finally

why you and all support only talk without direct solution ?????

June 22, 2016 at 7:17 am #923740

Dat Hoang

Please give us the exact flow you want, then we can support it better.
If you just give the code, and ask us to modify your code without any description and how it should work, how could our supporters help you correctly.

I hope you understand the point.

-----------

Going back to your question, I think you want to redirect clients to your own thank you pages for each language, right?

If so, based on your current code, you can use this code:

// thankyou page Start
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'] ) ) {
		$my_current_lang = apply_filters( 'wpml_current_language', NULL );
		if ( 'es' == $my_current_lang ) {
				wp_redirect( '<em><u>hidden link</u></em>' );
		}
		
		if ( 'en' == $my_current_lang ) {
				wp_redirect( '<em><u>hidden link</u></em>' );
		}
		
		exit;
    }
}
// thankyou page End
July 3, 2016 at 3:47 am #940544

attiahA

Thanks