Skip to content

Instantly share code, notes, and snippets.

@virtualize
Last active June 8, 2021 16:47
Show Gist options
  • Save virtualize/3f621a9ec91850b80cbcfa15222fa538 to your computer and use it in GitHub Desktop.
Save virtualize/3f621a9ec91850b80cbcfa15222fa538 to your computer and use it in GitHub Desktop.
Edit Shopify metafields in bulk editor, without an app

Metafields can be added to products, variants, collections, etc.

We add a simple bookmark to our browser that contains some javascript, called a bookmarklet. When the bookmarklet gets clicked it modifies the url and reloads the browser with it.

Create bookmarklet

  1. Create a new bookmark in your browser
  2. Enter a descriptive name of your liking
  3. Copy/paste the javascript from below into the location/url field of the bookmark

Bookmarklet to manually enter metafields names:

javascript: function reload () { const href = document.location.href; const regex = /(admin\/bulk\?resource_name=\w+&edit=)(.+?)&(.*)/; if (!regex.test(href)) { alert('This is not a bulk edit page'); return; } let fieldnames = prompt('Metafield name ( separate multiple by comma)', 'unpublished_at'); const metafields = fieldnames.split(',').map((name) => { return 'metafields.global.'+name.trim()+'%3Astring'; }).join('%2C'); document.location = href.replace(regex, '$1'+metafields+'$3'); }; reload();

Bookmarklet for single ('unpublished_at') metafield:

javascript: function reload () { const fieldname = 'unpublished_at'; const href = document.location.href; const regex = /(admin\/bulk\?resource_name=\w+&edit=)(.+?)&(.*)/; if (!regex.test(href)) { alert('This is not a bulk edit page'); return; } document.location = href.replace(regex, '$1metafields.global.'+fieldname+'%3Astring$3'); }; reload();

Edit metafields in bulk editor

For products:

  1. open products list in Shopify admin
  2. select one or more products from list by checkbox
  3. click "edit products" action button
  4. click bookmarklet from within your browser
  5. this bookmarklet will ask your for the metafield name you want to edit
  6. the shopify page reloads with the chosen metafields to edit

For variants:

  1. select a single product to edit in Shopify admin
  2. under variants, check the "select all" checkbox
  3. click "open bulk editor" action button
  4. continue as above
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment