hey @lukem538;
Assuming the payment-options page is located at /checkout/paymentoptions, then this code snippet excludes that specific page from being autoptimized;
add_filter('autoptimize_filter_noptimize','staff_noptimize',10,0);
function staff_noptimize() {
if (strpos($_SERVER['REQUEST_URI'],'checkout/paymentoptions')!==false) {
return true;
} else {
return false;
}
}
Alternatively you could go through the troubleshooting-steps in the AO FAQ to try to identify what JS is the culprit and try to fix by excluding that.
Hope this helps,
frank
Hi Frank,
We tried the script but that didn’t work. Then I tried to work out which .js files are being used on the page but this looks to be multiple files and depends on which payment gateway option the user selects so i think it would be better if we can exclude it via a script.
The location where users manage their own payments is
/my-account/settings/add-payment-method/
and
/my-account/settings/payment-methods/
Could you confirm what script we need and where it needs to be added?, our dev guy tried it on the functions.php is that correct?
Thanks
Luke
In that case I would suggest to use this code;
add_filter('autoptimize_filter_noptimize','staff_noptimize',10,0);
function staff_noptimize() {
if (strpos($_SERVER['REQUEST_URI'],'payment-method')!==false) {
return true;
} else {
return false;
}
}
and the easiest and safest way to add it would be using the code snippets plugin.
Hi thanks for the quick feedback. I have tried the script using code snippet but its not working?
Presume its as simple as create a new code snippet, add a description and text, run snippet everywhere and clear the cache?
If I have not missed anything unfortunately its still not working.
add new snippet -> paste snippet -> run everywhere (or front-end only) -> save and activate
so did you activate (had this problem myself on several occasions already to be honest 😉 )
Yes, its definitely activated. Guess the script apply to any url which contains –
“payment-method”
yes is does (apply to any URL which contains payment-method)
but it seems AO isn’t even running now anyhow?
Yes, I am testing the issue by accessing the payment methods with JavaScript Options in AO toggled on or off. If i disable JavaScript Options its working fine. But the site is so much slower 🙂
I have this disabled on live so users can amend payments but I am testing on our staging site which is setup for sandbox with braintree.
OK, so can you on live;
* enable AO with HTML & CSS optimization
* activate the code snippet
that will allow me to do _some_ tests on your live without any adverse effects on your customers 😉
Could you drop me an email as you will need a user account to access the logged in pages?
Luke.maxwell@earlyyearsstaffroom.com
update; code snippet was added on production and the payment-option pages were indeed not optimized any more, payment options and changing payment options worked.