Personalized checkout and custom promotions with Shopify Scripts
On the Account page, a button that I made. There will be an Order id value on the button. The Order tag on the order id that is sent from the button will be updated when the button is clicked. But I'm unable to solve my CORS issue. I have no idea how to resolve it. Kindly let me know.
Here my code:
function updateOrderTags(orderId) {
const shopifyStore = 'Shopify_id';
const accessToken = 'Token';
const updateTagsUrl = `https://${shopifyStore}.myshopify.com/admin/api/2023-10/orders/${orderId}.json`;
var xhr = new XMLHttpRequest();
xhr.open('PUT', updateTagsUrl, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('X-Shopify-Access-Token', accessToken);
xhr.withCredentials = true;
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 300) {
console.log('Success:', xhr.responseText);
customerRequireTaxModal.show();
} else {
console.error('Error:', xhr.status, xhr.statusText, xhr.responseText);
}
};
xhr.onerror = function () {
console.error('Network Error');
};
xhr.send(JSON.stringify({
order: {
id: orderId,
tags: 'TaxInvoice',
},
}));
}
var customerRequireTaxModal = new bootstrap.Modal(document.getElementById('customerRequireTax'));
document.querySelector('.tax.invoice a').addEventListener('click', function () {
var orderId = this.getAttribute('data-order-id');
updateOrderTags(orderId);
});
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024