Skip to content

Instantly share code, notes, and snippets.

@carolineschnapp
Last active June 21, 2021 20:39
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save carolineschnapp/b48349343df2302c9266 to your computer and use it in GitHub Desktop.
Save carolineschnapp/b48349343df2302c9266 to your computer and use it in GitHub Desktop.
Handpick your relevant collection for related products using the Custom Fields extension by freakdesign. #metafields

Instructions

  1. Get Google Chrome.

  2. Install the Chrome extension ShopifyFD. Direct link to install extension.

  3. Install the Chrome extension Custom Fields. Direct link to install extension.

  4. Go to your shop main settings page. Just click here once you're logged-in the right store.

  5. On that page, click on the Shopify FD icon in your extensions bar. It's a green icon with a plus sign in the center. Doing that will load the following form on the page: http://take.ms/Cy5wz

  6. Right under Add New Metafield, enter c_f. (Means 'custom field')

  7. Below that, type Related Products. (Or whatever, but that will impact the Liquid you'll need later.)

  8. And below that, type [p][_c]Pick a collection to pull related items from on this product's page. ( [p] means to add to product pages only, and [_c] means a collection picker, and what follows are instructions for merchants, you can change those instructions. )

  9. Click on the SAVE button right below the form. ( Not the Save button at the top of the page, you turkey. )

  10. Go to any product page in your admin where you want to handpick your 'relevant collection'.

  11. On that page, click on the Custom Fields icon in your extensions bar. It's a pink icon, you can't miss it. That will load the following on the page: http://take.ms/ZmhhD

  12. Pick your collection in the 'Pick a collection' drop-down.

  13. Click on the Save Custom Fields button on the left, NOT the 'Save (without Custom Fields)' button at the top of the page.

  14. Then add this bit of code at the very top of your related-products.liquid snippet:

{% if product.metafields.c_f['Related Products'] %}
 {% assign collection = collections[product.metafields.c_f['Related Products']] %}
{% endif %}

As a result of adding the code at the top of your snippet, it will be business as usual if you have not handpicked a collection for a particular product: the collection in scope will be used if it's relevant, and if not some other one.

Repeat steps 10 to 13 for any product where you want to handpick a relevant collection for related products.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment