At a shop level, I created a metafield for disabled dates as shown in the image below, that I want to retrieve and assign to a LIQUID variable in the code following the image.
Code in cart page:
window.addEventListener("load", function() {
// Don't add 0 before month and date to make it two digit.
//var disabledDays = ["2022-5-30","2022-7-4","2022-9-5","2022-11-24","2022-12-23","2022-12-24","2022-12-25","2022-12-30","2022-12-31","2023-1-1","2023-1-2"];
disabledDays = {{ shop.metafields.disabledDays.value }};
var minDate = new Date();
var maxDate = new Date();
maxDate.setDate((maxDate.getDate()) + 60);
minDaysToShip = 2; // Default minimum days
if (minDate.getDay() == 5) {
// Friday. Set min day to Tuesday. 4 days from now.
minDaysToShip = 4;
} else if (minDate.getDay() == 6) {
I see that {{ shop.metafields.disabledDates.value }};
is not reading the metadata content. Please show me the right way to do it.
If you are in a .liquid file, the following syntax should work for string type metafields:
{{ shop.metafields.disabledDays.disabledDays }}
Shopify added more metafield types and the new ones can indeed be accessed through the .value key, see this thread for more details: https://community.shopify.com/c/technical-q-a/how-to-access-json-data-from-the-new-shopify-native-metafields/td-p/1258088