-
-
Save bewho/3feadaaed9b1fe282a439d28a31d7ac0 to your computer and use it in GitHub Desktop.
WooCommerce force SSL entire shop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Author: Doug Edgington | |
Description: modified version of Woocomemrce SSL functionality, forces ssl on Woocommerce pages and two additional custom pages | |
*/ | |
function dee_ssl_template_redirect() { | |
if ( ! is_ssl() ) { | |
if ( is_checkout() || is_account_page() || is_woocommerce() ) { | |
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { | |
wp_safe_redirect( preg_replace( '|^http://|', 'https://', $_SERVER['REQUEST_URI'] ) ); | |
exit; | |
} else { | |
wp_safe_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); | |
exit; | |
} | |
} | |
} | |
// Break out of SSL if we leave woocommerce pages or custom pages | |
elseif ( is_ssl() && $_SERVER['REQUEST_URI'] && ! is_checkout() && ! is_page( woocommerce_get_page_id('thanks') ) && ! is_ajax() && ! is_account_page()) { | |
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { | |
wp_safe_redirect( preg_replace( '|^https://|', 'http://', $_SERVER['REQUEST_URI'] ) ); | |
exit; | |
} else { | |
wp_safe_redirect( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); | |
exit; | |
} | |
} | |
} //end function | |
add_action( 'template_redirect', 'dee_ssl_template_redirect', 1 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment