2015年4月21日 星期二

Add Cloudflare SSL to Woocommerce checkout page (avoiding the redirect loop)


使用WooCommerce,免不了會遇到SSL問題。

這是一篇解決方法的文章,現在用不到,不過先學起來總沒錯。



文章來源:
http://www.affiliatewebdesigners.com/2015/03/08/add-cloudflare-ssl-to-woocommerce-checkout-page-avoiding-the-redirect-loop/


Add Cloudflare SSL to Woocommerce checkout page (avoiding the redirect loop)


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).
?
1
2
3
4
5
6
7
8
9
10
11
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>
<?
}

沒有留言:

張貼留言