Instantly share code, notes, and snippets.

Embed
What would you like to do?
Forces WPML language settings to stop breaking the WooCommerce REST API
function wpml_wc_api_home_url( $url, $path, $orig_scheme, $blog_id ) {
global $sitepress;
if ( isset( $sitepress ) && 0 === strpos( $path, 'wc-api/' ) ) {
$url = $sitepress->convert_url( str_replace( $path, '', $url ), $sitepress->get_default_language() );
$url = untrailingslashit( $url ) . '/' . ltrim( $path, '/' );
}
return $url;
}
add_filter( 'home_url', 'wpml_wc_api_home_url', 0, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment