With Cloudflare you get an SSL certificate for free. But, if you’re using Woocommerce, like a lot of WordPress users, then the setting inside WooCommerce to Force SSL causes a ‘redirect loop’ on your checkout page.
This is because your SSL is happening via the Cloudflare proxy so the WordPress is_ssl() function can’t detect that you’re on SSL and keeps on redirecting to the SSL page forever.
There is a way around this however – Javascript can detect if the page is loaded via SSL correctly – and if not, redirect your users to the SSL page.
Modify the little code snippet below to use your website domain name instead of the Affiliate Web Designers domain name and then paste the code into your themes functions.php file (or add a new plugin containing this code snippet if you prefer).
add_action('woocommerce_before_checkout_form', 'cloudflaressloncheckout', 10); function cloudflaressloncheckout() { ?> <script language="javascript"> if (document.location.protocol != "https:") { document.location.href = "https://www.affiliatewebdesigners.com" + document.location.pathname; }; </script> <? }
- My WordPress performance plugins and server stack have moved - July 31, 2016
- Price Comparison Pro 1.2 Released - July 5, 2016
- How to run backups on huge WordPress websites without your website being brought offline - February 4, 2016
July 21, 2015 @ 4:30 am
Wondering if you could help me. I am having this exact problem with woo coomerce and flexible cloudflare SSL
thanks
January 31, 2016 @ 7:15 am
Thanks again! Another awesome suggestion.
I downloaded this WooThemes plug-in to make sure your code would last through any upgrades.
https://github.com/woothemes/theme-customisations
April 30, 2016 @ 12:47 pm
My boss loves you. :*
May 27, 2016 @ 1:54 pm
Aw thanks!