Contact form Drop Down with choices being a metafield

Contact form Drop Down with choices being a metafield

DavidCab
Shopify Partner
68 3 22

I want to add a dropdown to my contact form.

I want the choices to list all SKUs from my store.

Instead of listing each SKU on my own in the code, can I use a SKU metafield or some other way to do this with code? 

 

Replies 2 (2)

Kani
Shopify Partner
468 125 232

Hi @DavidCab 

 

You can send request via ajax to search page

/search?type=product&q=SKU

 Then render the result as you want.

Hey!! ʕ ᵔᴥᵔ ʔ
Please click 'Like' and ' Accept as Solution' to encourage me to continue sharing my expertise. ♡
If you need any technical assistance, feel free to send me a DM. You no longer have to search for answers without getting a response. 🙂

PaulNewton
Shopify Partner
7722 678 1627

 


@DavidCab wrote:

choices to list all SKUs from my store.

 

Liquid paginates to have a 50 product object limit per page, if you have ALOT of skus you will need advanced techniques.

Additionally if you have a lot of product skus , < 50  just listing all skus in a contact form is poor UX , greater than 100 is just bad and a search|filter method should be used.

 

For the output you sort the skus so the list is alphabetical,, and probably to use the uniq filter on any arrays being processed to remove duplicate skus , in addition to html encoding any sku values for the form submission.

 

For a handful of products this is just using a product loop on a collection setup to have all products in .

{%- assign skus = collections.all.products | map:"variants" | map: "sku" -%}
<select>
{%- for sku in skus -%}
 <option value="{{sku}}">{{sku}}</option>
{%- endfor -%}
</select>

 

Or a map filter to build the <option> elements for use with some javascript&colon;

<label for="">Choose a SKU</label>
<select name="">
 {{ collections.all.products | map:"variants" | map: "sku" | join:"<br /><option>" | split:"<br />" | join:"</option>" | prepend:"<option>" | append:"</option>" }} 
</select>

Note the attributes (for & name) need to be made for what contact form submission expects, and that the <option> tags get rendered with no value attribute.

 

If you need this built out you can contact me, info in sig.

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org