Creating a Metafield to Only Pull First 2 Digits of SKU

Solved

Creating a Metafield to Only Pull First 2 Digits of SKU

grimesa09
Shopify Partner
2 0 0

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!

Accepted Solution (1)

Joanet1
Shopify Partner
9 2 1

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

View solution in original post

Replies 3 (3)

Joanet1
Shopify Partner
9 2 1

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

grimesa09
Shopify Partner
2 0 0

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!

Joanet1
Shopify Partner
9 2 1

sorry but I'm not familiar with that app