Skip Navigation

Open

Reported for: WooCommerce Multilingual & Multicurrency 5.3.2

Topic Tags: Bug, WCML

Overview of the issue

When using WooCommerce Multilingual, setting the my-account page as a child of the shop page can lead to 404 errors accessing My Account endpoints (like Orders, Downloads, etc.) in secondary languages. This issue typically occurs with permalink settings like Shop base with category or Shop base.

Workaround

Please, make sure of having a full backup of your site before proceeding.

  • Open theme’s functions.php file.
  • Add the following code:
    add_filter( 'init', function() {
        $my_account_page_id   = wc_get_page_id( 'myaccount' );
        $my_account_parent_id = get_post_parent( $my_account_page_id );
        if ( $my_account_page_id && $my_account_parent_id ) {
            $default_language = apply_filters( 'wpml_default_language', '' );
            $languages        = apply_filters( 'wpml_active_languages', [] );
            foreach ( $languages as $language ) {
                if ( $language['code'] !== $default_language ) {
                    $translated_id  = apply_filters( 'wpml_object_id', $my_account_page_id, 'page', true, $language['code'] );
                    if ( $translated_id ) {
                        $translated_url = get_page_uri( $translated_id );
                        add_rewrite_rule( trailingslashit( $translated_url ) . '?$' , 'index.php?pagename=' . $translated_url, 'top' );
                        foreach ( WC()->query->query_vars as $endpoint ) {
                            $translated_endpoint = apply_filters( 'wpml_get_endpoint_translation', $endpoint, $endpoint, $language['code'] );
                            add_rewrite_rule( trailingslashit( $translated_url ) . $translated_endpoint . '(/(.*))?/?$' , 'index.php?' . $endpoint . '=$matches[2]&pagename=' . $translated_url, 'top' );
                        }
                    }
                }
            }
        }
    } );
    

Leave a Reply

Please stay on topic and be respectful to others. If you need help with issues not related to this post, use our Support Forum to start a chat or submit a ticket.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>