Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Return ID of translated WooCommerce page
<?php
/*
Plugin Name: Return translated WooCommerce page
Plugin URI: http://www.damiencarbery.com
Description: Required Polylang plugin. Returns ID of translated page.
Author: Damien Carbery
Version: 0.1
*/
// A safe version of code suggested at:
// https://jesperln.dk/how-to-make-woocommerce-work-with-polylang-wordpress/
add_filter( 'woocommerce_get_myaccount_page_id', 'polylang_get_translated_woocommerce_page_id' );
add_filter( 'woocommerce_get_edit_address_page_id', 'polylang_get_translated_woocommerce_page_id' );
add_filter( 'woocommerce_get_shop_page_id', 'polylang_get_translated_woocommerce_page_id' );
add_filter( 'woocommerce_get_cart_page_id', 'polylang_get_translated_woocommerce_page_id' );
add_filter( 'woocommerce_get_checkout_page_id', 'polylang_get_translated_woocommerce_page_id' );
add_filter( 'woocommerce_get_pay_page_id', 'polylang_get_translated_woocommerce_page_id' );
add_filter( 'woocommerce_get_view_order_page_id', 'polylang_get_translated_woocommerce_page_id' );
add_filter( 'woocommerce_get_terms_page_id', 'polylang_get_translated_woocommerce_page_id' );
function polylang_get_translated_woocommerce_page_id( $page_id ) {
if ( function_exists( 'pll_get_post' ) ) {
return pll_get_post( $page_id );
}
return $page_id
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.