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

Viewing 2 posts - 31 through 32 (of 32 total)
  • Posted in: Atelier
  • #216065
    alibey
    Member
    Post count: 179

    hi david,

    i added one extra line of code, as shown below, and it solved the problem in chrome, ie, ff, and opera.
    basically i applied a “magic” hack in the case where items have been deleted from the cart in order to break the infinite loop in your original code where the user unfortunately keeps cycling back to the empty cart page after deleting the last product in a cart.
    i know my addition would probably cause jquery purists to blanch and mumble in tongues, but it works in all test cases correctly. also no need for HTML5 local storage after all, as i previously thought, so no browser dependency.
    behavior of site is now as follows:
    the end user is returned to page 1 of the catalog, in the case where 1 item is deleted and no items remain in the cart.
    this also works correctly when 1 item is deleted, and items remain in the cart (clicking on the continue shopping also returns the user to page 1 of the catalog).
    finally in the case where the user is on the cart page and wants to continue shopping (and no items have been deleted, ie the cart lists 1 or more products), it correctly takes them back to wherever they came from (whether it is the first page of the catalog, or some other random page).

    that of course was the original requirement, which atelier/woocommerce out of the box does not support, but which you were kind enough to supply a jquery custom solution that partially solved the problem

    as an aside, you guys might want to consider adding this sort of functionality in a future release of atelier, as it is really useful and a time saver to the end user. my tweeking of your customization alas does NOT allow for the user to return to the page of origin after deleting the last item in a cart list, but this hack is good enough for my client at this point and it will be included when the site goes live next week.

    jQuery(document).ready(function() {
        
       var referrer =  document.referrer;
       var defaultURL = 'https://needlepoint.land/index.php/catalog-2/';
       
    
       if   // this tests the condition if a product has been removed and there are no more in the cart
            (document.URL 
            == 'https://needlepoint.land/index.php/cart/?removed_item=1')
          {
           jQuery("a.continue-shopping").prop("href", HAX);  // magic hack
       }
       
    // now you can invoke the referrer if there are 1 or more items left in the cart
       
       if ( referrer ) {
            jQuery("a.continue-shopping").prop("href", referrer);
            jQuery("a.button.wc-backward").prop("href", referrer);
            
            
       } else {
            jQuery("a.continue-shopping").prop("href", defaultURL);
       }
       
       
       
    });
    #216071
    David Martin – Support
    Moderator
    Post count: 20834

    Glad you got it, thanks for sharing the code also!

    -David.

Viewing 2 posts - 31 through 32 (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