WooCommerce REST API with JavaScript

With WordPress REST API i can simply fetch posts or anything available with JavaScript Fetch API or something similar.

Since WooCommerce REST API have auth keys the only way to fetch something is having the keys as query parameters, but i can’t expose the keys in JavaScript. So how can i do it safely?

const site_url = ‘https://example.com’;

fetch(`${site_url}/wp-json/wp/v2/posts/`)
.then(response => response.json())
.then(posts => {
posts.forEach(post => {
console.log(post.title.rendered);
});
});

Read more here:: WooCommerce REST API with JavaScript

Leave a Reply

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