How to Fix SyntaxError: Unexpected token < in JSON at position Error in WooCommerce & WordPress (Midtrans Case)

How to Fix SyntaxError: Unexpected token < in JSON at position Error in WooCommerce & WordPress (Midtrans Case) ?

This morning my team reported some chats on customer success department said that they cannot do the payment because after clicked Submit button on checkout form, there’s an error .

It’s a WordPress & WooCommerce based website.

The error message is:

SyntaxError: Unexpected token < in JSON at position 1

In this case we use Midtrans (Indonesian based payment gateway provider, group of Go-Jek) as our payment gateway. I did googling and found that several threads also talk about payment gateway.

Investigation

I checked the request by using Inspect Element on Chrome when submitting data on checkout form.

On Headers > General > Request URL: It shows that the Request URL goes to:
<domain>/<custom landing page>/wc-ajax=checkout

Meanwhile, on our Midtrans account it should be this (no sub directory after the domain):

Then I tried to figure out what made the difference. After crosscheck with developer, they confirmed that the home page was redirected 301 to <custom landing page> by .htaccess file.

We just aware that simple redirection on home could affect the vital part on the tail of business proces.

Conclusion

Now it’s crystal clear that the redirection made the WooCommerce read the link in wrong way.

It may be different with another case, but you should check first by doing Inspect Element to know the missing part.

P.S: I can help you to increase your business by integrating payment gateway to your current website or build from scratch a business oriented website with payment gateway feature. Wanna free consultantion? Let’s chat!

Leave a Comment

Your email address will not be published. Required fields are marked *