How do I use get_permalink() on an SSL Checkout page for WooCommerce?

Objective: I’m trying to fetch the permalink for a WordPress page so that I can use it if necessary in a javascript function after the page has been loaded. On all pages on the site, I can use the following and it works just fine.

$url = get_permalink();

Context: However, WooCommerce offers the ability to have SSL on the checkout page only rather than sitewide. When this is the case, get_permalink() always returns the non-SSL version of the link.

Read More

Problem: As a result, if I use that link for any type of a get request, it creates an SSL error for attempting to fetch a non-secure resource on a secure page.

How can this be fixed?

Related posts