Change the link of Login/Register button

Hello,
I’m trying to edit the link of Login/Register button on the header.
I succeeded once after reading this article.

However, I got js error after updating woocommerce plugin and the theme.

Here is what I did.

  1. I copied and pasted this code on functions.php in my child-theme directory.
        /**
     * Get WC page URL
     */
    add_action( 'wp_enqueue_scripts', 'leto_child_wc_pages', 9999 );
    function leto_child_wc_pages() {

      $wc_pages = array(
        'my_account' => get_permalink( wc_get_page_id( 'myaccount' ) ),
      );

      wp_localize_script( 'leto-main', 'wc_pages', $wc_pages );

    }
  1. I created a new js file (javascript.js) in the child-theme directory and wrote the code below in it.
    (function($){

      if( $('.nav-link-account a').length ) {
        $('.nav-link-account a').attr('href', wc_pages.my_account);
      }

    })(jQuery);
  1. I wrote the code below in the child theme functions.php
   add_action( 'wp_enqueue_scripts', function() {
        wp_enqueue_script( 'my_script', 
        get_stylesheet_directory_uri().'/javascript.js', 
        array('jquery'), '1.0.0', true);
   });

Then I got the js error which says “wc_pages is not defined”
Does anyone know what I did wrong?

Kind Regards,

Midori

Hello there,

Please check if you have enabled the account page. From WooCommerce’s settings panel, go to Advanced tab and see “My account page” row.

Regards,
Kharis

Hi Kharis,

Thank you for your reply.
I checked the woocommerce settings and My account page was set to My account.

Best regard,
Midori

Hello Midori,

Please share a link to your site, so I can have a look.

Regards,
Kharis

Hi Kharis,

My website is not launched yet.
Is there any way to send you a direct message so that I can give you ID and PASS.

Best,
Midori

Hello Midori,

I just sent you a direct message. Please reply it to share the login username and password. Before doing so, enable this plugin

Regards,
Kharis