Barjinder
Barjinder

Reputation: 107

Need to add query string in url from select option

I need to add query string from select option to sort out products as "Price Low to High" as default option when page load, here you can check products showing in collection t-shirt https://soft-theme.myshopify.com/collections/t-shirts and default option is "Newest to Oldest" and I want to change this "Price Low to High" as default option as you can see from dropdown of Sort By when we select "Price Low to high" its get change to https://soft-theme.myshopify.com/collections/t-shirts?sort_by=price-ascending

I just want this as default when page open first time.

http://prntscr.com/ehqmep

Upvotes: 0

Views: 473

Answers (1)

Nomi Ali
Nomi Ali

Reputation: 2252

You can do this by trigger a specific event you want to show by default in jquery. First provide the ID to the dropdown li like

<ul class="dropdown-menu" role="menu" selected="selected">
        <li><a id="id1" href="manual">Featured</a></li>
        <li><a id="id2" id="test" href="price-ascending">Price: Low to High</a></li>
        <li><a id="id3" href="price-descending">Price: High to Low</a></li>
        <li><a id="id4" href="title-ascending">A-Z</a></li>
        <li><a id="id5" href="title-descending">Z-A</a></li>
        <li><a id="id6" href="created-ascending">Oldest to Newest</a></li>
        <li><a id="id7" href="created-descending">Newest to Oldest</a></li>
        <li><a id="id8" href="best-selling">Best Selling</a></li>
      </ul>

Then in jquery document ready function trigger the event like below

$(function(){
    $("#id2").click(); //as price low to high
});

Upvotes: 1

Related Questions