建立代码精彩片段若想为礼品包装选择
2022-05-30 13:42:10
建立代码精彩片段
若想为礼品包装选择项建立代码精彩片段,请实行下列实际操作:
PC:
在Shopify后台管理中,转到在线商店模板。
寻找要编写的模板,随后点击实际操作编写代码。
在Snippets文件目录中点击加上新精彩片段。
将您的代码片段取名为gift-wrapping
,随后点击建立代码精彩片段。您的代码片段文档将在代码编辑软件开启。
在这里过程中,您必须将一些代码粘贴到新的gift-wrapping
代码精彩片段文档中。您粘贴的代码在于您要怎样向顾客扣除礼品包装服务项目的花费:
ios系统:
在Shopify运用中,轻触店铺。
在营销渠道一部分中,轻触在线商店。
轻触Managethemes(管理方法模板)。
寻找要编写的模板,随后点击实际操作编写代码。
在Snippets文件目录中点击加上新精彩片段。
将您的代码片段取名为gift-wrapping
,随后点击建立代码精彩片段。您的代码片段文档将在代码编辑软件开启。
在这里过程中,您必须将一些代码粘贴到新的gift-wrapping
代码精彩片段文档中。您粘贴的代码在于您要怎样向顾客扣除礼品包装服务项目的花费:
安卓手机系统:
在Shopify运用中,轻触店铺。
在营销渠道一部分中,轻触在线商店。
轻触Managethemes(管理方法模板)。
寻找要编写的模板,随后点击实际操作编写代码。
在Snippets文件目录中点击加上新精彩片段。
将您的代码片段取名为gift-wrapping
,随后点击建立代码精彩片段。您的代码片段文档将在代码编辑软件开启。
在这里过程中,您必须将一些代码粘贴到新的gift-wrapping
代码精彩片段文档中。您粘贴的代码在于您要怎样向顾客扣除礼品包装服务项目的花费:
为礼品包装加上固定不动利率
粘贴下列代码并储存:
{%iflinklists.gift-wrapping.links.size0andlinklists.gift-wrapping.links.first.type==product_link%}divid=is-a-giftstyle=clear:left;margin:30px0class=clearfixrtepinputid=gift-wrappingtype=checkboxname=attributes[gift-wrapping]value=yes{%ifcart.attributes.gift-wrapping%}checked=checked{%endif%}style=float:none/labelfor=gift-wrappingstyle=display:inline;padding-left:5px;float:none;For{{linklists.gift-wrapping.links.first.object.price|money}}pleasewraptheproductsinthisorder./label/pplabelstyle=display:blockfor=gift-noteGiftmessage(freeandoptional):/labeltextareaname=attributes[gift-note]id=gift-note{{cart.attributes.gift-note}}/textarea/p/div{%assignid=linklists.gift-wrapping.links.first.object.variants.first.id%}{%assigngift_wraps_in_cart=0%}{%foritemincart.items%}{%ifitem.id==id%}{%assigngift_wraps_in_cart=item.quantity%}{%endif%}{%endfor%}style#updates_{{id}}{display:none;}/stylescriptShopify.Cart=Shopify.Cart||{};Shopify.Cart.GiftWrap={};Shopify.Cart.GiftWrap.set=function(){varheaders=newHeaders({Content-Type:application/json});varrequest={method:POST,headers:headers,body:JSON.stringify({updates:{{{id}}:1},attributes:{gift-wrapping:true}})};fetch(/cart/update.js,request).then(function(){location.href=/cart;});}Shopify.Cart.GiftWrap.remove=function(){varheaders=newHeaders({Content-Type:application/json});varrequest={method:POST,headers:headers,body:JSON.stringify({updates:{{{id}}:0},attributes:{gift-wrapping:,gift-note:}})};fetch(/cart/update.js,request).then(function(){location.href=/cart;});}//Ifwehavenothingbutgift-wrapitemsinthecart.{%ifcart.items.size==1andgift_wraps_in_cart0%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.remove();});//Ifwehavemorethanonegift-wrapiteminthecart.{%elsifgift_wraps_in_cart1%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.set();});//Ifwehaveagift-wrapiteminthecartbutourgift-wrappingcartattributehasnotbeenset.{%elsifgift_wraps_in_cart0andcart.attributes.gift-wrapping==blank%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.set();});//Ifwehavenogift-wrapiteminthecartbutourgift-wrappingcartattributehasbeenset.{%elsifgift_wraps_in_cart==0andcart.attributes.gift-wrapping!=blank%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.set();});{%endif%}//Whenthegift-wrappingcheckboxischeckedorunchecked.document.addEventListener(DOMContentLoaded,function(){document.querySelector([name=attributes[gift-wrapping]]).addEventListener(change,function(event){if(event.target.checked){Shopify.Cart.GiftWrap.set();}else{Shopify.Cart.GiftWrap.remove();}});document.querySelector(#gift-note).addEventListener(change,function(evt){varnote=evt.target.value;varheaders=newHeaders({Content-Type:application/json});varrequest={method:POST,headers:headers,body:JSON.stringify({attributes:{gift-note:note}})};fetch(/cart/update.js,request);});});/script{%else%}pstyle=clear:left;margin:30px0class=rteYouattemptedtoaddagift-wrappingscripttoyourshoppingcart,butitwontworkbecauseyoudonthavealinklistwithhandlecodegift-wrapping/codewhich,inturn,containsalinktoyourgift-wrappingproduct.Pleasereviewthestepsoutlinedahref=https://help.shopify.com/manual/online-store/themes/os/customize/add-gift-wrap-optiontarget=_blankrel=noopenernoreferrernofollowhere/a./p{%endif%}
加上花费并乘于订单信息中的商品数
应用此选择项时,假如订单信息有三件商品,则礼品包装花费将乘于3。粘贴下列代码并储存:
{%iflinklists.gift-wrapping.links.size0andlinklists.gift-wrapping.links.first.type==product_link%}divid=is-a-giftstyle=clear:left;margin:30px0class=clearfixrtepinputid=gift-wrappingtype=checkboxname=attributes[gift-wrapping]value=yes{%ifcart.attributes.gift-wrapping%}checked=checked{%endif%}style=float:none/labelfor=gift-wrappingstyle=display:inline;padding-left:5px;float:none;For{{linklists.gift-wrapping.links.first.object.price|money}}peritem,pleasewraptheproductsinthisorder./label/pplabelstyle=display:blockfor=gift-noteGiftmessage(freeandoptional):/labeltextareaname=attributes[gift-note]id=gift-note{{cart.attributes.gift-note}}/textarea/p/div{%assignid=linklists.gift-wrapping.links.first.object.variants.first.id%}{%assigngift_wraps_in_cart=0%}{%foritemincart.items%}{%ifitem.id==id%}{%assigngift_wraps_in_cart=item.quantity%}{%endif%}{%endfor%}{%assignitems_in_cart=cart.item_count|minus:gift_wraps_in_cart%}style#updates_{{id}}{display:none;}/stylescriptShopify.Cart=Shopify.Cart||{};Shopify.Cart.GiftWrap={};Shopify.Cart.GiftWrap.set=function(){varheaders=newHeaders({Content-Type:application/json});varrequest={method:POST,headers:headers,body:JSON.stringify({updates:{{{id}}:{{items_in_cart}}},attributes:{gift-wrapping:true}})};fetch(/cart/update.js,request).then(function(){location.href=/cart;});}Shopify.Cart.GiftWrap.remove=function(){varheaders=newHeaders({Content-Type:application/json});varrequest={method:POST,headers:headers,body:JSON.stringify({updates:{{{id}}:0},attributes:{gift-wrapping:,gift-note:}})};fetch(/cart/update.js,request).then(function(){location.href=/cart;});}//Ifwehavenothingbutgift-wrapitemsinthecart.{%ifcart.items.size==1andgift_wraps_in_cart0%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.remove();});//Ifwedonthavetherightamountofgift-wrapitemsinthecart.{%elsifgift_wraps_in_cart0andgift_wraps_in_cart!=items_in_cart%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.set();});//Ifwehaveagift-wrapiteminthecartbutourgift-wrappingcartattributehasnotbeenset.{%elsifgift_wraps_in_cart0andcart.attributes.gift-wrapping==blank%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.set();});//Ifwehavenogift-wrapiteminthecartbutourgift-wrappingcartattributehasbeenset.{%elsifgift_wraps_in_cart==0andcart.attributes.gift-wrapping!=blank%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.set();});{%endif%}//Whenthegift-wrappingcheckboxischeckedorunchecked.document.addEventListener(DOMContentLoaded,function(){document.querySelector([name=attributes[gift-wrapping]]).addEventListener(change,function(event){if(event.target.checked){Shopify.Cart.GiftWrap.set();}else{Shopify.Cart.GiftWrap.remove();}});document.querySelector(#gift-note).addEventListener(change,function(evt){varnote=evt.target.value;varheaders=newHeaders({Content-Type:application/json});varrequest={method:POST,headers:headers,body:JSON.stringify({attributes:{gift-note:note}})};fetch(/cart/update.js,request);});});/script{%else%}pstyle=clear:left;margin:30px0class=rteYouattemptedtoaddagift-wrappingscripttoyourshoppingcart,butitwontworkbecauseyoudonthavealinklistwithhandlecodegift-wrapping/codewhich,inturn,containsalinktoyourgift-wrappingproduct.Pleasereviewthestepsoutlinedahref=https://help.shopify.com/manual/online-store/themes/os/customize/add-gift-wrap-optiontarget=_blankrel=noopenernoreferrernofollowhere/a./p{%endif%}
在购物车模板中包括代码精彩片段
若想在购物车模板中包含礼品袋代码精彩片段,请实行下列实际操作:
在Sections文件目录中,点击cart-template.liquid
。假如您的模板中并没有cart-template.liquid
,请点击Templates文件目录中的cart.liquid
。
搜索代码中的完毕/form
标识。在完毕/form
标识上边的新行中,黏贴下列代码:
{%rendergift-wrapping%}
点击储存。
Shopify商家官方网站原文详细信息:
Createacodesnippet
Tocreateacodesnippetforthegift-wrapoption:
PC:
FromyourShopifyadmin,gotoOnlineStoreThemes.
Findthethemeyouwanttoedit,andthenclickActionsEditcode.
IntheSnippetsdirectory,clickAddanewsnippet.
Nameyoursnippet
gift-wrapping
andclickCreatesnippet.Yoursnippetfilewillopeninthecodeeditor.Inthisstep,youwillpastesomecodeintoyournew
gift-wrapping
snippetfile.Thecodeyoupastedependsonhowyouwanttochargeyourcustomersforthegiftwrappingservice:iPhone:
FromtheShopifyapp,tapStore.
IntheSaleschannelssection,tapOnlineStore.
TapManagethemes.
Findthethemeyouwanttoedit,andthenclickActionsEditcode.
IntheSnippetsdirectory,clickAddanewsnippet.
Nameyoursnippet
gift-wrapping
andclickCreatesnippet.Yoursnippetfilewillopeninthecodeeditor.Inthisstep,youwillpastesomecodeintoyournew
gift-wrapping
snippetfile.Thecodeyoupastedependsonhowyouwanttochargeyourcustomersforthegiftwrappingservice:Android:
FromtheShopifyapp,tapStore.
IntheSaleschannelssection,tapOnlineStore.
TapManagethemes.
Findthethemeyouwanttoedit,andthenclickActionsEditcode.
IntheSnippetsdirectory,clickAddanewsnippet.
Nameyoursnippet
gift-wrapping
andclickCreatesnippet.Yoursnippetfilewillopeninthecodeeditor.Inthisstep,youwillpastesomecodeintoyournew
gift-wrapping
snippetfile.Thecodeyoupastedependsonhowyouwanttochargeyourcustomersforthegiftwrappingservice:Addaflatratechargeforgiftwrapping
PastethefollowingcodeandSave:
{%iflinklists.gift-wrapping.links.size0andlinklists.gift-wrapping.links.first.type==product_link%}divid=is-a-giftstyle=clear:left;margin:30px0class=clearfixrtepinputid=gift-wrappingtype=checkboxname=attributes[gift-wrapping]value=yes{%ifcart.attributes.gift-wrapping%}checked=checked{%endif%}style=float:none/labelfor=gift-wrappingstyle=display:inline;padding-left:5px;float:none;For{{linklists.gift-wrapping.links.first.object.price|money}}pleasewraptheproductsinthisorder./label/pplabelstyle=display:blockfor=gift-noteGiftmessage(freeandoptional):/labeltextareaname=attributes[gift-note]id=gift-note{{cart.attributes.gift-note}}/textarea/p/div{%assignid=linklists.gift-wrapping.links.first.object.variants.first.id%}{%assigngift_wraps_in_cart=0%}{%foritemincart.items%}{%ifitem.id==id%}{%assigngift_wraps_in_cart=item.quantity%}{%endif%}{%endfor%}style#updates_{{id}}{display:none;}/stylescriptShopify.Cart=Shopify.Cart||{};Shopify.Cart.GiftWrap={};Shopify.Cart.GiftWrap.set=function(){varheaders=newHeaders({Content-Type:application/json});varrequest={method:POST,headers:headers,body:JSON.stringify({updates:{{{id}}:1},attributes:{gift-wrapping:true}})};fetch(/cart/update.js,request).then(function(){location.href=/cart;});}Shopify.Cart.GiftWrap.remove=function(){varheaders=newHeaders({Content-Type:application/json});varrequest={method:POST,headers:headers,body:JSON.stringify({updates:{{{id}}:0},attributes:{gift-wrapping:,gift-note:}})};fetch(/cart/update.js,request).then(function(){location.href=/cart;});}//Ifwehavenothingbutgift-wrapitemsinthecart.{%ifcart.items.size==1andgift_wraps_in_cart0%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.remove();});//Ifwehavemorethanonegift-wrapiteminthecart.{%elsifgift_wraps_in_cart1%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.set();});//Ifwehaveagift-wrapiteminthecartbutourgift-wrappingcartattributehasnotbeenset.{%elsifgift_wraps_in_cart0andcart.attributes.gift-wrapping==blank%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.set();});//Ifwehavenogift-wrapiteminthecartbutourgift-wrappingcartattributehasbeenset.{%elsifgift_wraps_in_cart==0andcart.attributes.gift-wrapping!=blank%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.set();});{%endif%}//Whenthegift-wrappingcheckboxischeckedorunchecked.document.addEventListener(DOMContentLoaded,function(){document.querySelector([name=attributes[gift-wrapping]]).addEventListener(change,function(event){if(event.target.checked){Shopify.Cart.GiftWrap.set();}else{Shopify.Cart.GiftWrap.remove();}});document.querySelector(#gift-note).addEventListener(change,function(evt){varnote=evt.target.value;varheaders=newHeaders({Content-Type:application/json});varrequest={method:POST,headers:headers,body:JSON.stringify({attributes:{gift-note:note}})};fetch(/cart/update.js,request);});});/script{%else%}pstyle=clear:left;margin:30px0class=rteYouattemptedtoaddagift-wrappingscripttoyourshoppingcart,butitwontworkbecauseyoudonthavealinklistwithhandlecodegift-wrapping/codewhich,inturn,containsalinktoyourgift-wrappingproduct.Pleasereviewthestepsoutlinedahref=https://help.shopify.com/manual/online-store/themes/os/customize/add-gift-wrap-optiontarget=_blankrel=noopenernoreferrernofollowhere/a./p{%endif%}
Addachargethatismultipliedbythenumberofproductsintheorder
Withthisoption,iftherearethreeproductsintheorder,thenthegiftwrapchargewillbemultipliedbythree.PastethefollowingcodeandSave:
{%iflinklists.gift-wrapping.links.size0andlinklists.gift-wrapping.links.first.type==product_link%}divid=is-a-giftstyle=clear:left;margin:30px0class=clearfixrtepinputid=gift-wrappingtype=checkboxname=attributes[gift-wrapping]value=yes{%ifcart.attributes.gift-wrapping%}checked=checked{%endif%}style=float:none/labelfor=gift-wrappingstyle=display:inline;padding-left:5px;float:none;For{{linklists.gift-wrapping.links.first.object.price|money}}peritem,pleasewraptheproductsinthisorder./label/pplabelstyle=display:blockfor=gift-noteGiftmessage(freeandoptional):/labeltextareaname=attributes[gift-note]id=gift-note{{cart.attributes.gift-note}}/textarea/p/div{%assignid=linklists.gift-wrapping.links.first.object.variants.first.id%}{%assigngift_wraps_in_cart=0%}{%foritemincart.items%}{%ifitem.id==id%}{%assigngift_wraps_in_cart=item.quantity%}{%endif%}{%endfor%}{%assignitems_in_cart=cart.item_count|minus:gift_wraps_in_cart%}style#updates_{{id}}{display:none;}/stylescriptShopify.Cart=Shopify.Cart||{};Shopify.Cart.GiftWrap={};Shopify.Cart.GiftWrap.set=function(){varheaders=newHeaders({Content-Type:application/json});varrequest={method:POST,headers:headers,body:JSON.stringify({updates:{{{id}}:{{items_in_cart}}},attributes:{gift-wrapping:true}})};fetch(/cart/update.js,request).then(function(){location.href=/cart;});}Shopify.Cart.GiftWrap.remove=function(){varheaders=newHeaders({Content-Type:application/json});varrequest={method:POST,headers:headers,body:JSON.stringify({updates:{{{id}}:0},attributes:{gift-wrapping:,gift-note:}})};fetch(/cart/update.js,request).then(function(){location.href=/cart;});}//Ifwehavenothingbutgift-wrapitemsinthecart.{%ifcart.items.size==1andgift_wraps_in_cart0%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.remove();});//Ifwedonthavetherightamountofgift-wrapitemsinthecart.{%elsifgift_wraps_in_cart0andgift_wraps_in_cart!=items_in_cart%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.set();});//Ifwehaveagift-wrapiteminthecartbutourgift-wrappingcartattributehasnotbeenset.{%elsifgift_wraps_in_cart0andcart.attributes.gift-wrapping==blank%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.set();});//Ifwehavenogift-wrapiteminthecartbutourgift-wrappingcartattributehasbeenset.{%elsifgift_wraps_in_cart==0andcart.attributes.gift-wrapping!=blank%}document.addEventListener(DOMContentLoaded,function(){Shopify.Cart.GiftWrap.set();});{%endif%}//Whenthegift-wrappingcheckboxischeckedorunchecked.document.addEventListener(DOMContentLoaded,function(){document.querySelector([name=attributes[gift-wrapping]]).addEventListener(change,function(event){if(event.target.checked){Shopify.Cart.GiftWrap.set();}else{Shopify.Cart.GiftWrap.remove();}});document.querySelector(#gift-note).addEventListener(change,function(evt){varnote=evt.target.value;varheaders=newHeaders({Content-Type:application/json});varrequest={method:POST,headers:headers,body:JSON.stringify({attributes:{gift-note:note}})};fetch(/cart/update.js,request);});});/script{%else%}pstyle=clear:left;margin:30px0class=rteYouattemptedtoaddagift-wrappingscripttoyourshoppingcart,butitwontworkbecauseyoudonthavealinklistwithhandlecodegift-wrapping/codewhich,inturn,containsalinktoyourgift-wrappingproduct.Pleasereviewthestepsoutlinedahref=https://help.shopify.com/manual/online-store/themes/os/customize/add-gift-wrap-optiontarget=_blankrel=noopenernoreferrernofollowhere/a./p{%endif%}
Includethesnippetinyourcarttemplate
Toincludethegift-wrappingsnippetinyourcarttemplate:
IntheSectionsdirectory,click
cart-template.liquid
.Ifyourthemedoesnthaveacart-template.liquid
,thenclickcart.liquid
intheTemplatesdirectory.Findtheclosing
/form
taginthecode.Onanewlineabovetheclosing/form
tag,pastethefollowingcode:{%rendergift-wrapping%}
ClickSave.
文章内容由来:Shopify商户官方网站
部分文章来源于网络,如有侵权,请联系 caihong@youzan.com 删除。