Last active
December 20, 2015 12:59
-
-
Save dougedgington/6135573 to your computer and use it in GitHub Desktop.
Force SSL on Woocommerce pages and two additional custom pages
This file contains hidden or 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_page(48) || is_page(64) ) { | |
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() && ! is_page(48) && ! is_page(64) ) { | |
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
The original functions this was built from have since been changed.
You can now accomplish this using the filters "woocommerce_force_ssl_checkout" and "woocommerce_unforce_ssl_checkout" within your function.php or plugin.
There's no need to check is_ssl() here since that's done before the filters are applied.