ylliX - Online Advertising Network

How to make Woocommerce pages work with Polylang?

This can be really frustrating, you wanted your woocommerce shop running multilingual, but from cart page “Checkout” button leads to default language version? Solution is very simple, but not elegant – so far did not found another solution. First step is to create all woocommerce pages in every language you need, this is very simple but can take some time. Then, in your child theme (remember not to make any modifications to theme you are using!), in functions.php add such code:

function get_woocommerce_checkout_polylang()
{
    return pll_get_post(get_option('woocommerce_checkout_page_id' ) );
}
add_filter('woocommerce_get_checkout_page_id', "get_woocommerce_checkout_polylang");

function get_woocommerce_shop_polylang()
{
    return pll_get_post(get_option('woocommerce_shop_page_id' ) );
}
add_filter('woocommerce_get_shop_page_id', "get_woocommerce_shop_polylang");

function get_woocommerce_cart_polylang()
{
    return pll_get_post(get_option('woocommerce_cart_page_id' ) );
}
add_filter('woocommerce_cart_page_id', "get_woocommerce_cart_polylang");

function get_woocommerce_pay_polylang()
{
    return pll_get_post(get_option('woocommerce_pay_page_id' ) );
}
add_filter('woocommerce_pay_page_id', "get_woocommerce_pay_polylang");

function get_woocommerce_thanks_polylang()
{
    return pll_get_post(get_option('woocommerce_thanks_page_id' ) );
}
add_filter('woocommerce_thanks_page_id', "get_woocommerce_thanks_polylang");

function get_woocommerce_myaccount_polylang()
{
    return pll_get_post(get_option('woocommerce_myaccount_page_id' ) );
}
add_filter('woocommerce_myaccount_page_id', "get_woocommerce_myaccount_polylang");

function get_woocommerce_edit_address_polylang()
{
    return pll_get_post(get_option('woocommerce_edit_address_page_id' ) );
}
add_filter('woocommerce_edit_address_page_id', "get_woocommerce_edit_address_polylang");

function get_woocommerce_view_order_polylang()
{
    return pll_get_post(get_option('woocommerce_view_order_page_id' ) );
}
add_filter('woocommerce_view_order_page_id', "get_woocommerce_view_order_polylang");

function get_woocommerce_terms_polylang()
{
    return pll_get_post(get_option('woocommerce_terms_page_id' ) );
}
add_filter('woocommerce_terms_page_id', "get_woocommerce_terms_polylang");

All those functions are using same pll_get_post from Polylang plugin, to translate your default page ID you set in Woocommerce/Settings/Checkout/Checkout Pages to their translated version. Hope you will find it useful.

3 thoughts on “How to make Woocommerce pages work with Polylang?

  1. Hi, I’d like to know if this works with woocommerce myaccount endpoints? It seems like the links generated are still pointing to the main language !
    thank you !

  2. Excellent! I had the problem with the checkout page. Now it is fixed!
    Still works in 2022!! Thank you for publishing these lines.
    Regards,

Leave a Reply