Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

WooCommerce force https issue with Network Solutions WordPress

  • SOLVED

Need help on getting Woocommerce secure on Network Solutions. There is a known issue and they have offered up this info

Network Solutions offers the following code as the best redirect available from http:// to https:// in Javascript, saying that there is no way to do it server side.

<script language="javascript">
if (document.location.protocol != "https:")
{
document.location.href = "https://subdomain.yourdomain.com" + document.location.pathname;
};
</script>

to be found at http://www.networksolutions.com/support/ssl-redirects/

I mainly need to know where I would put this javascript and how I would specify that it allows either woocommerce to use its force https or if I would need to put in individual web pages to specify.

Answers (1)

2013-05-22

Yakir Sitbon answers:

in functions.php:

function ys_wp_footer_force_ssl() {
?>
<script type="text/javascript">
if (document.location.protocol != "https:") {
document.location.href = "https://subdomain.yourdomain.com" + document.location.pathname;
}
</script>
<?php
}
add_action( 'wp_footer', 'ys_wp_footer_force_ssl' );


Have fun.


movino4me comments:

So the only thing I need to do is to put the secure location of the site or what is the + document.location.pathname;
for.

For instance the site name would be https://www.mysite.com
One of the woocommerce page needed to be secure is https://www.mysite.com/products-page/checkout/

So how would this look in the code?


Yakir Sitbon comments:

Are you need this for one page only?


movino4me comments:

As far as I can tell but if you could give me both options just in case I come across another it would be great. currently it is mainly the send info and credit card pages but I guess I should include the error pages so it does not pop in and out of secure.
Lets go with multiple, if you use the same web address for multiple and I can see the separator for adding more then I will replace the addresses.

Thanks


Yakir Sitbon comments:

function ys_wp_footer_force_ssl() {
$pages = array(
'/products-page/checkout/',
'/other-page/'
);
// End edit.

if ( empty( $pages ) )
return;

foreach ( $pages as &$page ) {
$page = sprintf( '"%s" == document.location.pathname', $page );
}
?>
<script type="text/javascript">
alert( document.location.pathname) ;
if (document.location.protocol != "https:") {
if ( <?php echo implode( ' || ', $pages ); ?> ) {
document.location.href = "https://subdomain.yourdomain.com" + document.location.pathname;
}
}
</script>
<?php
}
add_action( 'wp_footer', 'ys_wp_footer_force_ssl' );


You are should edit $pages array only.
Good day :)


Yakir Sitbon comments:

Oops.. Code again..

function ys_wp_footer_force_ssl() {
$pages = array(
'/products-page/checkout/',
'/other-page/'
);

// End edit.

if ( empty( $pages ) )
return;

foreach ( $pages as &$page ) {
$page = sprintf( '"%s" == document.location.pathname', $page );
}
?>
<script type="text/javascript">
if (document.location.protocol != "https:") {
if ( <?php echo implode( ' || ', $pages ); ?> ) {
document.location.href = "https://subdomain.yourdomain.com" + document.location.pathname;
}
}
</script>
<?php
}
add_action( 'wp_footer', 'ys_wp_footer_force_ssl' );


movino4me comments:

I apologize for the extra request but my hope is that you can insert the example links below so that I can make sure that I put the info in correctly. I will replace this test link with my correct versions once you insert it.

For instance the site name would be https://www.mysite.com
One of the woocommerce page needed to be secure is https://www.mysite.com/products-page/checkout/

So how would this look in the code?


Yakir Sitbon comments:

You just need change 'https://subdomain.yourdomain.com' to your domain (https://www.mysite.com).

I do not understand what wrong with my code.


movino4me comments:

Yakir, Nothing was wrong with your code except that I had requested that you insert the web site info into it to make sure that I was including it correctly. You had just reposted the same code without the sites included. The only question that still remains unanswered is that I gave two site address as examples and you only included the (https://www.mysite.com)

The part that I am unsure of is the following " + document.location.pathname;" What is this for and how is it used. Do I use the https://www.mysite.com as the "document.location.href = "https://www.mysite.com" as the base secure site and use the actual page that needs to be locked down for the document.location.pathname;? "https://www.mysite.com/products-page/checkout/" This is why I provided both so that you could let me know how to lock down multiple pages if necessary.


So in short, what does "+ document.location.pathname;" mean in this string and how would I include the test info that I gave to lay it out correctly?

document.location.href = "https://www.mysite.com" + document.location.pathname;


movino4me comments:

Yakir,

Can you be more specific as to where this code gets put. I am understanding that the network solutions code needs to be put on the actual checkout page to be active but I am not familiar as to where it actually goes. also ,do i need both codes, the one that network solutions gave and the one that you created?

Any specific help would be appreciated