How can I hide product variant ID from URL on Sense 5.0.1 theme?

Solved

How can I hide product variant ID from URL on Sense 5.0.1 theme?

MagnifyPixels
Tourist
5 1 0
  • I tried to look for a way to hide product variant id from the product variant pages url. I found out one way but it's not viable with my theme I'm using theme Sense 5.0.1.
    The way was to edit code in "product.liquid " if i reckon right, and the code to edit was from " data-enable-history-state="true"> " to " data-enable-history-state="false"> "
    This made you able to scroll trough variants without a change in the URL in the theme this solution was originally provided.
    I highly think it is not viable for my theme since I tried to find it from various page code files with no results. After that I inspected the product variant page and searched for "history" and there was no such value.
    I know it could be done by creating single product pages with redirects but its quite a hassle.
    Does anyone know is there a similar code to edit or snippet to add to my theme to make the same function mentioned above? Thanks.
  •  

    Kind Regards
    Nilla Maunu

Accepted Solution (1)

MagnifyPixels
Tourist
5 1 0

This is an accepted solution.

I figured it out: Go to edit code find folder: global.js in that folder search for:

 

updateURL() { if (!this.currentVariant || this.dataset.updateUrl === 'false') return; window.history.replaceState({}, '', `${this.dataset.url}?variant=${this.currentVariant.id}`); }

 

Replace with:

updateURL() {

if (!this.currentVariant || this.dataset.updateUrl === 'false'return;

}

View solution in original post

Reply 1 (1)

MagnifyPixels
Tourist
5 1 0

This is an accepted solution.

I figured it out: Go to edit code find folder: global.js in that folder search for:

 

updateURL() { if (!this.currentVariant || this.dataset.updateUrl === 'false') return; window.history.replaceState({}, '', `${this.dataset.url}?variant=${this.currentVariant.id}`); }

 

Replace with:

updateURL() {

if (!this.currentVariant || this.dataset.updateUrl === 'false'return;

}