Custom JavaScript for Ecommerce Shopify Site


I’ve just finished building a Shopify shop from scratch at:

Everything is working great, we’re just working out small bugs here and there. We have it set up to where, when someone clicks on the “Add to Pallet” button, it refreshes to the same page and lands back on that particular products div. We used Javascript to do this by using an anchor tag based on that products SKU number. So, if you add a product to your pallet, you can see in the address bar something like:

This works fine, but if the user adds another product on the same page, it amends that SKU number to the end of the other one, like so: Which makes the anchor not work.

So, I was just wondering if there’s a way to replace the SKU number every time someone adds another product instead of amending it…?

Are you using the location object to adjust the URL? For example, you can use location.hash to work with the fragment identifier.