Skip to content

Instantly share code, notes, and snippets.

@pablogiralt
Last active February 19, 2021 17:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablogiralt/0227fff6af5431750c85f7c47bd90479 to your computer and use it in GitHub Desktop.
Save pablogiralt/0227fff6af5431750c85f7c47bd90479 to your computer and use it in GitHub Desktop.
Add a size guide to Shopify Brooklyn Theme

Add Size Guide to Shopify Brooklyn Theme

This is what you get:

1- A link to below the variant selector which will open the size guide:

Shopify Brooklyn Theme Size Guide

2- The size selector modal:

Shopify Brooklyn Theme Size Guide

Step by Step Guide:

1- Open Sections/product-template.liquid and around line 198, below the variant selector, paste the following:

{% if product.options contains 'Size' %}
    <a class="size-guide__link" data-action="open-size-guide" href="#size-guide">
        Size guide
    </a>
{% endif %}

2- Still in Sections/product-template.liquid aftr rest of html, around line 261, paste this:

<div id="size-guide" class="size-guide__modal mfp-hide">
  {{ pages.size-guide.content }}
</div>

3- Open theme.js.liquid and search for this line:

    this._initShopifyXrLaunch();

(Should be around line 2829:)

And just below it paste the following line:

    this._initProductSizeChart(); 

Result should be this:

Shopify Brooklyn Theme Size Guide

4- Still in theme.js.liquid, search for this:

    _initShopifyXrLaunch: function() {
      $(document).on(
        'shopify_xr_launch',
        function() {
          var $currentMedia = $(
            this.selectors.productMediaWrapper +
              ':not(.' +
              this.classes.hide +
              ')',
            this.$container
          );
          $currentMedia.trigger('xrLaunch');
        }.bind(this)
      );
    },

(around line 2912)

And just below paste this:

    _initProductSizeChart: function() {
  		$('[data-action="open-size-guide"]').magnificPopup({
      		type:'inline',
      		midClick: true
    	});
    },

Result should be this:

Shopify Brooklyn Theme Size Guide

5- Open theme.scss.liquid and at the end of the file, paste this:

.size-guide__modal {
	background-color: #ffffff;
  	text-align: center;
  	padding: 20px;
  	max-width: 800px;
  	margin-left: auto;
  	margin-right: auto;
  	-webkit-box-shadow: 3px 3px 6px 0px rgba(0,0,0,0.41); 
  	box-shadow: 3px 3px 6px 0px rgba(0,0,0,0.41);
}

.size-guide__link {
	text-decoration: underline;
}

6- Create a page with handle size-guide and add the size chart in the page's content

Shopify Brooklyn Theme Size Guide

Make sure the handle is "size-guide"

Shopify Brooklyn Theme Size Guide

7- Enjoy your new size guide!

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