Skip to content

Snippet: Polylang Support for WooCommerce Buttons

This function filters the options you select in the WooCommerce settings for the shop, cart and checkout pages so that they return the correct page based on the current language for functions such as the add to cart button or the return to shop button.

function myprefix_translate_woo_pages( $page_id ) {
	if ( function_exists( 'pll_get_post' ) ) {
		$page_id = pll_get_post( $page_id );
	return $page_id;
add_filter( 'woocommerce_get_shop_page_id', 'myprefix_translate_woo_pages' );
add_filter( 'woocommerce_get_cart_page_id', 'myprefix_translate_woo_pages' );
add_filter( 'woocommerce_get_checkout_page_id', 'myprefix_translate_woo_pages' );
All PHP snippets should be added via child theme's functions.php file or via a plugin (we recommend WPCode)
Back To Top