- Admin
- Choosing to execute the script only for merchants
- Choosing to execute the script on the item details page, no matter who the user
- Choosing to execute a script only for merchants on the item-details page
- Choosing to execute a script only for merchants on the item-details page of Bespoke marketplaces only
- Choosing to execute a script only for buyers on item-details page of Bespoke marketplaces only
For admins, the task gets really easy. First, the code that’s supposed to run for admins is found only in the admin folder of your zip file. Secondly, it can be easily detected if an admin is logged on the admin dashboard with this:
var pathname = (window.location.pathname + window.location.search).toLowerCase();
var admin = '/admin';
if(pathname.indexOf(admin) > -1){
//do something
}if($('#merchantId') && $('#merchantId').length){
//do something
}if($("body").hasClass("item-detail-page")){
//do something
}if($('#merchantId') && $('#merchantId').length && $("body").hasClass("item-detail-page")){
//do something
}Choosing to execute a script only for merchants on the item-details page of Bespoke marketplaces only:
if($('#merchantId') && $('#merchantId').length && $("body").hasClass("item-detail-page")){
$('input').each(function(){
if($(this).attr('value') == 'bespoke'){
//do something
}
})
}Merchants and buyers have only 1 thing in common:
<input type = “hidden” id = “userId” value= “(somevalue)”>"</p>But buyers don’t have:
<input type = “hidden” id = “merchantId” value= “(somevalue)”>That’s why if we want to execute a script strictly for buyers, we write return 0
if a “merchantId” id is found.
if($('#merchantId') && $('#merchantId').length){
return 0;
} else {
if($('#userId') && $('#userId').length && $("body").hasClass("item-detail-page")){
$('input').each(function(){
if($(this).attr('value') == 'bespoke'){
//do something
}
})
}
}