foreign,what's up YouTube Welcome Back to,another edition of coding with Robbie my,name is Robbie and in this video we're,going to be covering Shopify meta Fields,so uh before we get started make sure to,like subscribe leave a comment let me,know you're there and uh yeah you're,probably wondering Robbie what's a meta,field well it is basically a place to,store additional data in Shopify so you,can add a meta field to products,collections your shop pretty much any,object in Shopify you can add a meta,fuel to and it's a little bit of a,hidden feature because if you're in your,admin dashboard there is no way to add a,meta field through this dashboard it can,only be done through the API so you have,to depend on an app to do this but,there's some really good apps out there,and it's uh not difficult at all and uh,yeah so what is this good for let me,kind of paint a scenario for you so say,we have a product page like this and,down here we have a specifications area,and really if you go to the product um,editor page,really the only place you get the store,data,sorry it's just taking a second to load,extremely long time to load that's weird,I just kind of ruined my whole segment,come on,what the Shopify,all right there we go they're really the,only place you get to uh store data is,the title description and media fields,and then there's some price and stuff,but you know there's really no place to,add specification data so you're,probably thinking oh we got settings why,don't you just use,um section settings so I kind of set,that up to show you the issue with that,so let's say we're on products I got my,default product and I got settings for,it right here but this is just for the,default product so say I have 20,products for every single one I'm gonna,have to uh create a new template and,let's call this one a leather jacket,and let's say hey the leather jacket,maybe it's you know,54 and 32 and we save it and that's,going to create an additional template,file on our theme and then we have to go,Within,products and we have to find the leather,jacket or really any product we want to,use it on,Shopify is really slow today and then I,gotta go hey I don't want to use the,default template I want to use that new,one I created and this is just going to,create a ton of bloat within your theme,you're going to end up with hundreds of,template files and it's just really a,bad way to do it so before we go any,further I'm just going to delete that,new template we created so let's go to,online store and just go to your theme,and go to edit code,and then find the newly created uh,product template mine's right here I'm,just going to trash it,there we go so in order to add meta,fields to your store you're going to,have to download an app if you just,search for meta fields on the App Store,there's a bunch of different ones and by,far the best app is meta Fields Guru so,I'd highly recommend this app you just,come here and add app and once you do,add it to your store you get to a,dashboard like this,and here's all the different objects you,can add meta fields to so you got,products variants collections orders,blog posts shop really anything,so let's rework our specifications table,right here to use meta Fields instead,so let's go to products and we want to,add it to our leather jacket,and we just hit create meta field and a,meta field has a type so there's a bunch,of different types you can use and for,our usage we're going to do dimension,and then a meta field has a namespace so,let's name space it specs and a key,let's call this height,and then we'll give it a value of 40.,inches and we'll just hit save and this,is going to add that data to our product,and now we can access that within our,section template file,so let's go to our template here's the,section right here and right here you,see I'm using the setting to show the,height let's change that to use our meta,field,so it's going to be product,dot meta fields and then we do the,namespace with respects and uh the key,which was height,so let's save that and see what happens,we'll go back to our product page and,I'll refresh,and it looks like that meta field is an,object that has key value and key unit,so let's go back here and let's go dot,value,and then we'll show the unit after so,let's copy this,and put dot unit,let's save that and refresh,and there we go it's now using that meta,field so now I could add that to all my,products and it won't create new,templates or anything,so we could go through and add meta,fields for each one but what's going to,be annoying is that say we do add all,three right here and then we go and do,another product,uh we're gonna have to recreate every,single one it's just gonna take a lot of,time so this app introduced a setting,called meta field sets and this,basically lets you pre-define a schema,so let's add one for products we'll call,this product specs,and then he could filter what products,you want it to show on I'm going to,leave it blank so it'll be all the,products I'll hit create and now we can,add the settings we want here so let's,uh create one that's a Boolean,when I find Boolean,right here we'll call this namespace,specs key has specs,and then we'll add one,oh we got to put a label too so let's,call this enable specs table,and then we'll do our Dimension Fields,right here so let's go Dimension specs,this one's going to be height,and then let's add another one for,length so this will also be a dimension,foreign,we have is thickness so let's go,Dimension again,expects thickness,hit save,so now we kind of declared What fields a,product should have so now if we go back,here we'll go to products again and say,we want to add it to our blue tuxedo we,go in here and we still don't see it but,now we have this tab up here called,Product specs we can click into that and,we have all our Fields predefined so we,can just go true our height maybe is 100,inches our length is,200 centimeters and our thickness is 45,millimeters hit save,and should have added all that data to,the blue tuxedo product and we can see,it right here now,so let's go to our blue tuxedo product,right here,and let's finish up uh hooking up our,meta fields to the template so I'll go,back here,and let's just copy this right here,so now we have land so let's paste that,in length and length,and then we have thickness so let's go,down here paste it again,thickness and then we added that has,specs uh Boolean field so maybe this,whole section doesn't show if we don't,have that meta field so let's go up here,and let's just go if,uh,product.metafields.specs dot has specs,if that's the case we'll show this,section otherwise we don't show anything,so let's close that up hit save and go,back to our page and now I refresh,we get 100 inches 200 centimeters 45,millimeters and then we go to a,different product and that section won't,show at all,to say I went to this product we don't,have it,so another cool thing we can do is we,can actually Loop through these specs,since they all have the same namespace,so let's go to our section file and,right here we're doing all the different,rows let's do a loop instead so right,here we can go four spec and,product.metafields.specs,um N4 and then for each one let's just,render out spec and see what happens,so just like that let's go back to our,tuxedo product,and we can see it rendering right here,and it's a little bit weird but it's an,array the zero position is the key and,the one position is the value,so to make this work we could um copy,our row right here and then we'll show,the key right here so let's go,um expect zero and then for the value it,would be,spec one dot value and for the unit it,would be,spec one dot unit just like that let's,delete these rows down here,that's my dog barking,let's go back and I'll refresh and there,we go it's rendering a row for each one,so really we should have put this has,specs in a different name space but,Loops can be pretty powerful with meta,fields and uh yeah that's pretty much,the formula for adding meta fields in,Shopify so we added it to a product but,this could be done on any object type,and you would just change it in your,code so say we added at the shop it,would be,shop.metafields.key dot value or if we,did it on order the order.meta fields,and yeah you can pretty much add it to,any object in Shopify and uh yeah I'd,encourage you to come in here and maybe,play with the different types so we did,Dimension but there's really all kinds,of different types and they all work the,same way so say we did date you just do,the date,tons of different stuff you can do so uh,I think that's pretty much it I hope you,enjoyed this video make sure to like And,subscribe and leave a comment let me,know you're there and I'll see you in,the next one bye
Congratulation! You bave finally finished reading how to add metafields in shopify and believe you bave enougb understending how to add metafields in shopify
Come on and read the rest of the article!