const wooClientKey = 'ck_00000000000000000000000000';
const wooClientSecret = 'cs_00000000000000000000000000';
const wooUrl = 'https://yoursite.com/wp-json/wc/v3/products';
function basicAuth(key, secret) {
let hash = btoa(key + ':' + secret);
return "Basic " + hash;
}
let auth = basicAuth(wooClientKey, wooClientSecret);
function getData(url) {
jQuery.ajax({
url: url,
method: 'GET',
beforeSend: function (req) {
req.setRequestHeader('Authorization', auth);
}
})
.done(function (data) {
console.log(data);
return data;
});
}
getData(wooUrl);