• Hi there…
    Previously I have changed add to cart button to contact button (tel and whatsapp) on single page product woocommerce. For users who are not logged in I hide the contact button then show the login button and registration button.

    On the other hand, I’m using a code snippet that will redirect to the previous/last page after the user has successfully logged in/registered. However for some reason I had to change the appearance of this login/register button using a modal and I have achieved it.

    So currently I have 2 versions :
    Old version -> login/register button using link,

    <button class="myBtn" onclick="window.location='https://mysite.com/login'">Login </button>

    New Version -> Login/register button using shortcode (modal),
    `<button id=”myBtn” class=”inline”>Masuk</button>
    <button id=”myBtn2″ class=”inline”>Daftar</button>`

    where the new version will replace the old version.(see screenshot)

    My question: How so that when a user logged in/registered via a modal is returned to the same page, not to the previous page?

    Some information that might help:

    Wordpress : Version 6.1

    Woocommerce : Version 7.0.1

    WP-Super Cache : Version 1.9.1

    Ultimate Member : Version 2.5.1

    UM SETTING FORM : Redirect after login on form setting -> default

    UM SETTING REDIRECT : See Screenshoot

    WP Setting Cache : See Screenshoot

    Code snippet after successful login:

    `add_action(“um_after_login_fields”, function(){
    if( isset( $_SERVER[‘HTTP_REFERER’] ) && !isset( $_REQUEST[‘redirect_to’] ) ){
    echo “<input type=’hidden’ name=’redirect_to’ value='”.esc_attr( $_SERVER[‘HTTP_REFERER’] ).”‘>”;
    }
    });`

    Code snippet after successful register :

    `add_action( ‘um_after_form_fields’, ‘my_after_form_fields’, 10, 1 );
    function my_after_form_fields( $args ) {
    if( isset( $_SERVER[‘HTTP_REFERER’] ) && !isset( $_REQUEST[‘redirect_to’] ) ){
    echo “<input type=’hidden’ name=’redirect_to’ value='”.esc_attr( $_SERVER[‘HTTP_REFERER’] ).”‘>”;
    }
    }

    do_action( ‘um_after_form_fields’, $args );`

    I have also done the following tests:

    mysite.com/product/home-for-sale-001 -> this is a single product page and let’s say we will call it an as HFS page.

    Case in point -> User do login or register with the following flow:
    1. First page opened : Home page -> go to shop page -> and then viewing HFS product page -> users login using log in button which is on site menu -> users successfully login and returned to HFS page.
    2. First page opened : Home page -> go to shop page -> and then viewing HFS product page -> Users logged in using old version login button which was on HFS page -> user logged in successfully and returned to HFS page.
    3. First page opened : Home page -> Go to shop page -> view HFS product page -> User login using new version (modal) login button which is on HFS page -> user login successfully but returned to shop page.
    4. First page opened: HFS product page -> login using new version button (modal) -> white / stuck site display . There are 2 ways I do it here:
    4a. Refreshing the page this way -> user already successfully logged in HFS page
    4b. Refreshing the page this way -> user is not logged in. However when repeating login in the same way (login button on modal), user successfully login (without white / stuck site display).

    Another note: In some previous tests, when the user failed to login there was a change in the url -> site.com/product/home-hor-sale-001/?err=invalid_nonce&um-hash=4e88kd. Then above the login page field there is a message -> An error has been encountered. Probably page was cached. Please try again. I’m not sure if this has anything to do with the action in the WP SETTING CACHE screenshot.

    Sorry if the delivery method from me is not good.

    And please let me know if any other information is needed.

    Thank you

    [Moderator note: Please, No bumping].

  • The topic ‘Redirect After Login (?err=invalid_nonce&um-hash=4e88kd)’ is closed to new replies.