Home / Blog / Web Design
Web Design

How to remove the SKU numbers from Ecwid in WordPress

How to remove the SKU numbers from Ecwid in WordPress

If you’re wanting to remove the SKU numbers from Ecwid in WordPress – To remove starting with “p-” from every Ecwid product, you can use the Ecwid API and JavaScript to fetch products, identify SKUs starting with “p-“, and then update them without this prefix.

Here’s a JavaScript code snippet for this:

				
					/* Add to Custom JS */
// Ecwid Store settings
const storeId = ‘YOUR_STORE_ID’;
const token = ‘YOUR_ACCESS_TOKEN’;
// Function to fetch all products
async function fetchAllProducts() {
const response = await fetch(`https://app.ecwid.com/api/v3/${storeId}/products?token=${token}`);
const data = await response.json();
return data.items;
}
// Function to update product SKU
async function updateProductSKU(productId, newSku) {
await fetch(`https://app.ecwid.com/api/v3/${storeId}/products/${productId}?token=${token}`, {
method: ‘PUT’,
headers: { ‘Content-Type’: ‘application/json’ },
body: JSON.stringify({ sku: newSku })
});
}
// Main function to process all products
async function processProducts() {
const products = await fetchAllProducts();
for (const product of products) {
if (product.sku && product.sku.startsWith(‘p-‘)) {
const newSku = product.sku.replace(/^p-/, ”);
await updateProductSKU(product.id, newSku);
console.log(`Updated SKU for product ID ${product.id}: ${newSku}`);
}
}
}
// Run the main function
processProducts().then(() => console.log(“SKU update process completed.”)).catch(console.error);
				
			

How to remove the SKU numbers from Ecwid in WordPress:

  1. Fetch ProductsfetchAllProducts retrieves all products from the Ecwid store.
  2. Check and Update SKU: For each product, if the SKU starts with “p-“, it removes “p-” and updates the SKU.
  3. Logging: Logs each SKU update for tracking.

Notes:


  • Replace YOUR_STORE_ID and YOUR_ACCESS_TOKEN with your Ecwid store’s ID and access token.

  • This example assumes all products can be fetched in a single call. For large inventories, implement pagination.

Make sure you test this in a controlled environment before using it in production.

You can get your Ecwid store ID from the bottom left of your dashboard:

Written by

[email protected]

Read more insights from our team on web design, paid ads, and growth strategy.

More articles Blog
Ready to grow?

Let us work together

Book a free strategy session with our team. No obligation, no pressure, just straight advice.

Book a Free Call Read more articles