Solutions to API errors when WordPress home and site address are different
-
Hi.I’m using Nginx’s reverse proxy to route en.example.com to example.com/en/.
Overall it works fine, but I am getting CORS errors on pages with woocommerce blocks inserted (such as Cart, Checkout).
Screenshot -> https://imgsh.net/a/sJGykIA.jpg
This issue will occur Gutenberg editor too.
However, I found that Gutenberg can work around this by using the following code to set the site address (site URL) to be the base for the API instead of the WordPress address (home URL).
// change WordPress API URL to HOME URL add_filter('rest_url', 'wptips_home_url_as_api_url'); function wptips_home_url_as_api_url($url) { $url = str_replace(home_url(),site_url() , $url); return $url; }
Could you please tell me if there’s any way to apply this code to the WooCommerce block, or if there’s another workaround?
Thank you.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Solutions to API errors when WordPress home and site address are different’ is closed to new replies.