New Landing How can we help? Atelier href redirect not working

Viewing 15 posts - 1 through 15 (of 32 total)
  • Posted in: Atelier
  • #214184
    alibey
    Member
    Post count: 179

    this is a continuation of an earlier topic from a few weeks ago.

    the situation is this: say a user goes to my HP, then clicks the Cart icon, then clicks on the Return to Shop box.
    I want the user to return to the HP, and not be sent the WooCommerce Shop page, which is the default behavior.

    here is the relevant Atelier HTML

    <a class="button wc-backward" href="https://needlepoint.land/index.php/catalog-2/">Return To Shop</a>

    I wrote a JS function that should work. This code has been examined by other programmers on Stackoverflow. This function was tested in other environments and it worked fine there. But it does not execute correctly on WP/Woocommerce/Atelier using O, FF, or Chrome.

    Can anyone at Swiftideas tell me if they know of something (some Atelier listener, for instance) that may be sitting on the server side and preventing/blocking the referrer string (or even a harcoded URL, which I also attempted to use as a redirect) from being assigned to the a element’s href?

    Is this an Atelier issue? Or is this some sort of browser sandbox thing?

    I may have to go to WP.org forums for further insight into solving this problem, but I thought I would first ask Swiftideas support for guidance.

    Here is the code (as you can see, I attempted several methods to perform the redirect):

     window.onload = function () {
            
            
            document.querySelector(".button.wc-backward").onclick = function() {
                
                // query selector works as expected
             
                var URLstring = document.referrer;  // works fine
                
                window.location.assign(URLstring);  // blocked
                
                window.location.href = URLstring;  // href unchanged, blocked
                
                setTimeout(function () {
                    window.location.href = URLstring; },100);  // blocked, even with delay
                
                return false;  // does not cancel default behavior
               
         
        }
    }

    Thanks as always for any help you can provide.

    #214189
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779
    This reply has been marked as private.
    #214193
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    I need to login to check in detail.
    Thanks
    Mohammad

    #214200
    David Martin – Support
    Moderator
    Post count: 20834

    Hi,

    If you use the Chrome web dev tools, do you also see the JS error?

    Uncaught TypeError: Cannot set property 'onclick' of null

    This is a very quick example of how I would do it with jQuery, though I would recommend you use PHP.

    jQuery(document).ready(function() {
       
       var referrer =  document.referrer;
       var defaultURL = 'http://google.com/cart';
       
       if ( referrer ) {
            jQuery("a.continue-shopping").prop("href", referrer);
            //console.log(referrer);
       } else {
            jQuery("a.continue-shopping").prop("href", defaultURL);
          // console.log("No refering URL set. Defaulting back to default cart URL.");
       }
       
    });

    All the best,
    David.

    #214211
    alibey
    Member
    Post count: 179
    This reply has been marked as private.
    #214212
    David Martin – Support
    Moderator
    Post count: 20834

    @alibey, have you tried the jQuery I provided? That works as required for me on my dev version.

    – David.

    #214213
    alibey
    Member
    Post count: 179
    This reply has been marked as private.
    #214214
    alibey
    Member
    Post count: 179

    > david, amendation, that was the error i was getting, until i got the css syntax right in the queryselector (no space between the classes fixed the problem). now chrome does not complain about anything and queryselector is working correctly as i am testing everything in the chrome console. but the href redirect is being blocked by something.

    #214217
    David Martin – Support
    Moderator
    Post count: 20834

    Seems to be work now with the supplied jQuery. #214200.

    – David

    #214218
    alibey
    Member
    Post count: 179

    > david jquery code not working. not sure why google.com/cart is specified as the default url.

    i know this may be old school, but it would be great to achieve this with plain old js. 😉

    #214223
    alibey
    Member
    Post count: 179

    jquery snippet chrome local scope watch

    Local
    <return>: undefined
    defaultURL: “http://google.com/cart&#8221;
    referrer: “https://needlepoint.land/&#8221;

    #214224
    David Martin – Support
    Moderator
    Post count: 20834

    Hi,

    That was a for you to change to your default cart URL of your choice. http://google.com/cart It was a place holder.

    I supplied you with a solution for how I would do it, which works. It changes the link to the referring URL if set, if not it defaults to the default URL variable defaultURL.

    Thanks,
    David.

    #214225
    alibey
    Member
    Post count: 179

    all right i am going to pose the question to the regular wp.org forum
    there must be something performing the redirect blocking, and i will be darned if i don’t find out what it is! thx for the help tho

    #214226
    alibey
    Member
    Post count: 179

    > david k. i see. will change default accordingly and see what happens. thanks again!

    #214227
    David Martin – Support
    Moderator
    Post count: 20834

    Not sure why you cannot use the supplied jQuery?

    – David.

Viewing 15 posts - 1 through 15 (of 32 total)

You must be logged in and have valid license to reply to this topic.

License required for the following item
Login and Registration Log in · Register