Changing "return to shop" URL for all languages with WPML plugin
Update2: In your code, you need to use:
- WooCommerce
wc_get_page_id()
function to get the WooCommerce shop page ID. - WPML
wpml_object_id
filter hook to get the current language translated page ID for shop. - WooCommerce
wc_get_page_permalink()
that is used by the filter hook itself (see HERE)
With that material, you can get the current translated link of the shop (or any other link).
So your code is going to be:
add_filter( 'woocommerce_return_to_shop_redirect', 'wc_empty_cart_redirect_url' );function wc_empty_cart_redirect_url() { // Getting the shop ID $shop_id = wc_get_page_id( 'shop' ); // Getting the current language ID for the shop page $current_lang_id = apply_filters( 'wpml_object_id', $shop_id, 'page', TRUE ); // Getting the post object for the ID $post = get_post($current_lang_id); // Getting the slug from this post object $slug = $post->post_name; // We re-use wc_get_page_permalink() function just like in this hook $link = wc_get_page_permalink( $slug ); return $link;}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Finally I tested and it works…