How to split arrays (example)

Our client has asked us to separate clothing items that have at least 2 sizes under a dedicated custom label. In this case we have all of items' sizes aligned as a string in the <size> parameter, like so:

In order to separate the items that have and at least 2 sizes, we will need to first split the sizes onto rows, add a rule that counts the rows and assigns them with a custom label parameter, then rejoin them back onto string form.


First and foremost, make sure to enable test mode and create a custom variable for size. Since we do not want to modify the original value itself, it's always a good idea to create a custom variable for experimental purposes and simply copy the value from the original parameter. For this example we will name the custom variable size_temp.

Having created the custom variable size_temp we will start off by copying the value to it from the original size parameter by creating a new rule. The following rule applies to all products.

Next, split the size_temp values (sizes) onto rows by using Split text funtion by ; sign (since this is our divider)

We have succesfully split the values onto a table.

Next, we will need to create another rule which we will use for assigning a custom label to products that have at least 2 or more sizes available. The product from our test mode has 3 sizes, so the following rule will apply

Having the above rule in tact, all products that contain at least 2 sizes will be assigned with a custom_label_1 variable "2 Sizes+". The size_temp variable will not be shown in the feed as it only served us for product categorization.