All things Shopify and commerce
I'm trying to figure out if there is a way to create a metafield that pulls the first two digits of a SKU.
I'm trying to run a report that shows the quantity of line items sold by the first two digits of the SKU.
I assumed a metafield would be the way to go about this, but I may be wrong, as I'm entirely new to metafields. Any help would be appreciated.
Thanks!
Solved! Go to the solution
This is an accepted solution.
You don't necessarily need a metafield for this! You can achieve this directly in your Liquid code when generating your report. Here's how you can extract the first two digits of the SKU:
{% assign first_two_digits = line_item.sku | slice: 0, 2 %}
{{ first_two_digits }}
Then, in your report generation, you can group or filter by this first_two_digits variable. This avoids the need for a metafield altogether, which simplifies things
This is an accepted solution.
You don't necessarily need a metafield for this! You can achieve this directly in your Liquid code when generating your report. Here's how you can extract the first two digits of the SKU:
{% assign first_two_digits = line_item.sku | slice: 0, 2 %}
{{ first_two_digits }}
Then, in your report generation, you can group or filter by this first_two_digits variable. This avoids the need for a metafield altogether, which simplifies things
Thanks so much for your reply. Where do I add it to the code?
I'm using the Xporter app to run my reports. Will I be able to access this is a field there?
Thanks again!
sorry but I'm not familiar with that app
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025