Digital experiences for all disciplines
New Landing › How can we help? › Atelier › href redirect not working
New Landing › How can we help? › Atelier › href redirect not working
- This topic has 31 replies, 4 voices, and was last updated 9 years by David Martin – Support.
-
Posted in: Atelier
-
September 17, 2015 at 4:08 pm #214228
You should use the code I provided is the official way to do it in Woocommerce, you just need to copy those to the functions.
There is a lot of stuff in Woocommerce and WordPress core functions that handles the redirections so a custom js solution in this case may be difficult to achieve.Also notice you have a custom permalink structure that could be interfering.
I just tested in my dev site and it works fine.
-Rui
September 17, 2015 at 4:37 pm #214246> david thank you for the supplied jquery.
unfortunately, it is being ignored. perhaps i did something wrong. all i did was cut and pasteit into the swift custom js window, and removing the comment forward slashes from the console calls. i am sure i have to set some obscure switch somewhere to make the interpreter recognize it. for some reason, this is starting to get way to complicated for something as simple as this. i cannot understand why this env is so unique that a standard, technically correct javascript func does not work here. and now suddenly the onclick js that worked last night (and was tested in other envs) no longer works correctly here. this is really starting to be beyond my limited comprehension ability actually, and frankly extremely non productive. but again, thank you for the jquery routine which alas is being ignored by the wp shmagilla. i am dropping this is telling the client it cannot be done, period.
jQuery(document).ready(function() {
var referrer = document.referrer;
var defaultURL = ‘https://needlepoint.land/index.php/catalog-2/’;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.”);
}});
September 17, 2015 at 4:42 pm #214251Hi,
It can be done, I have it working.
This reason it was not working is because you have copied my jQuery into your JS function
window.onload = function() {
Please remove all your custom JS. Simply leaving my supplied code.
Best,
David.September 17, 2015 at 6:02 pm #214330> david hi
actually i had commented out all my custom js functions
now i have trashed them entirely and saved just your jquery functionit still does not work
obviously i am doing something wrong somehow and it is completely beyond me how to fix to i am just going to drop it.
again thx!September 17, 2015 at 6:45 pm #214333Ok, no problem!
Cheers,
David.September 17, 2015 at 7:51 pm #214344it is now in the hands of the wordpress.org gurus.
there is no reason your solution (or mine, for that matter) should not work in my prod env.
it is almost a lost cause trying to debug your jquery as the chrome debugger throws me into this unreadable jquery library, even after i blackbox jquery.i refuse to let this go, as it defies reason and common sense, and programming to me after all is said and done is about logic not vodoo magic where code only works here but not there every other sunday except when it rains.
cheers.
September 18, 2015 at 9:43 am #214405Hi,
If you remove all JS from your theme options JS box, I’ll get it to work for you.
—
You desired logic is: If someone visits your checkout page, get the referring URL and update the continue shopping link with the referring URL?
September 18, 2015 at 3:32 pm #214550David,
as they say in NY (where I’m from, by way of the Midlands UK), you’re a mensch!
I have deleted all custom JS.The owner of the site considers all traffic on the site as a form of shopping (as oppposed
to her more social media presence on fb and needlepointland.com, where
she receives considerable amounts of daily traffic
and where she is often asked by people outside of florida — ie not in
her fla B&M) how to buy her products, hence
the need for needlepoint.land)thus returning to any referrer page is logical shop-related navigation
from a UI/UX perspective and does not
require changing any HTML text on any Return to Shop box or hyperlinkso her requirement is
use case 1:
say a customer is in the middle of the catalog (or the HP, or any other page)
eg
https://needlepoint.land/index.php/catalog-2/page/3/
customer clicks on the empty cart icon
customer is now here
https://needlepoint.land/index.php/cart/
customer clicks on Return to Shop box
customer returns to
https://needlepoint.land/index.php/catalog-2/page/3/use case 2:
say a customer is in the middle of the catalog
https://needlepoint.land/index.php/catalog-2/page/3/
customer adds a product to the cart (either from this page, or the product page)
customer clicks on Continue shopping hyperlink
customer returns to
https://needlepoint.land/index.php/catalog-2/page/3/use case 3:
same as above, except customer deletes product from cart, then
same behavior as use case 1Many thanks!!!
September 18, 2015 at 3:58 pm #214563Ah, I did not account for the empty cart situation which is possible where we were getting mixed up.
I have amended the JS in your theme options and I believe that works for your three user test cases.
Would you mind giving it a test?
– David.
September 18, 2015 at 4:26 pm #214572almost perfect except in use case 3
specifically
customer adds a product to the cart
customer goes to view cart page
customer deletes product from cart
the empty cart page is now displayed (https://needlepoint.land/index.php/cart/)
customer clicks on Return to Shop
the customer again sees https://needlepoint.land/index.php/cart/
instead of original referrer pageso it looks like an original referrer var has to be declared in the function
then that is the one used to href back, no matter where the customer goes after thatSeptember 18, 2015 at 5:38 pm #214610any luck?
thx!
September 18, 2015 at 7:57 pm #214655i tried to get fancy and added a global local storage var
to make the initial referring value persistent across
page loads but no go.your code still works, however! (but users still get caught in a loop after deleting a product unless they swipe or click back)
cheers
September 21, 2015 at 11:23 am #214936Hi,
Unfortunately I would not be able to modify that for case 3, I would not be able to detect the difference between an empty cart and if a user has clicked remove cart, for 1 or more items in the cart.
– David.
September 21, 2015 at 5:17 pm #215150well… the actual logic is quite simple, of course, for case 3
first time in, save referrer val to global variable
user deletes the product from the cart
page refreshes automatically
now the current url is equal to the referring url
this is the problem
your function should test for this: if the above == TRUE, then return to PREVIOUS REFERRER value (the saved global var)that logic should solve for this state, but I can’t quite it to work properly — it probably has to do with the onload global var function being invoked every time the page reloads, when I only want this to happen once — when the document loads the first time. basically i want a static global variable a la C++ but I cant quite figure out how to do it in js. i thought HTML5 solved that problem with local storage.
here is the code (which does not quite work in case 3, and thus I disabled both functions on the web site)
/* window.onload = function () { if(typeof(Storage) !== "undefined") { localStorage.setItem("initialReferrer", 0); } else { alert("Your browser does not support Web Storage"); } } jQuery(document).ready(function() { var referrer = document.referrer; var defaultURL = 'https://needlepoint.land/index.php/catalog-2/'; if (localStorage.getItem("initialReferrer") == referrer) { jQuery("a.continue-shopping").prop("href", initialReferrer); jQuery("a.button.wc-backward").prop("href", initialReferrer); return true; } if ( referrer ) { jQuery("a.continue-shopping").prop("href", referrer); jQuery("a.button.wc-backward").prop("href", referrer); localStorage.setItem("initialReferrer", referrer); return true; } else { jQuery("a.continue-shopping").prop("href", defaultURL); } });
I will ask the stackoverflow gurus for some insight, as the WordPress.org board seems pretty useless.
September 21, 2015 at 6:16 pm #215165Yeah, unfortunately this modification would be out of the scope of support.
StackOverflow should give you an answer if you outline a reduced test case and some code, if not you would need a web developer, as you know we recommend WerkPress.
I would still look to do this with PHP as functions exists within WooCommerce which would allow you to easily do this. Ex, is cart empty:
WC()->cart->get_cart_contents_count() == 0
.Cheers,
David. -
Posted in: Atelier
You must be logged in and have valid license to reply to this topic.