Shopify themes, liquid, logos, and UX
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
Hi,
I would like to know if there is any app or solution that can print the items in the cart into a table format, or export/save the cart as PDF or CSV?
Your help is really appreciated.
Thanks,
Azie
To export your cart data as a CSV file, you can use a simple JavaScript solution. This works by grabbing the contents of the cart using Shopify's fetch API, then formatting that data into a CSV file that you can download. It's straightforward to set up and will allow customers to save their cart in CSV format.
example
function exportCartToCSV() {
fetch('/cart.js')
.then(response => response.json())
.then(cart => {
let csvContent = "data:text/csv;charset=utf-8,Product Name,Quantity,Price\n";
cart.items.forEach(item => {
csvContent += `${item.title},${item.quantity},${item.price / 100}\n`;
});
let encodedUri = encodeURI(csvContent);
let link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "cart.csv");
document.body.appendChild(link);
link.click();
});
}