Skip to main content

I am processing orders from Woocommerce and sending to Xero. I have some products with similar SKUs which I want to simplify. (Woo won’t allow duplicate SKUs). I have entered the SKUs to have common details, followed by a hyphen and then the bits I want removed. 
 

How can I replace (with nothing) all text after a given character in a line item?

As an example below are some SKUs I have and what I want them to be. Replace would do it, but I can only get it to replace a whole known string not a string with wildcard. 

Input              Required out

650Hi             650Hi

650Hi-Eco      650Hi

659Hi-Paint    650Hi

 

I had thought doing Find/Replace -* with inothing] was the kind of thing I was looking for. 

Any thoughts gratefully received  

 

Hi @JasonAndre 

You can use a Zap Code step: https://zapier.com/apps/code/help

Code step also has AI: https://help.zapier.com/hc/en-us/articles/15666688064013-Generate-a-Code-step-using-AI-Beta

 

CODE

// Extract SKU from line item and remove text after hyphen
const lineItem = inputData.line_item; // Assuming 'line_item' is the variable containing the SKU
const hyphenIndex = lineItem.indexOf('-'); // Find the index of the hyphen
const simplifiedSKU = hyphenIndex !== -1 ? lineItem.substring(0, hyphenIndex) : lineItem;

// Assign the simplified SKU to the output field
output = { simplified_sku: simplifiedSKU };

 

Feedback from ChatGPT

 


@JasonAndre 

Another approach using Formatter > Text > Split (which handles line items)