Reputation: 1955
I'm working on a shopify project now. I've something like this to make the delivery unavailable for specified day offs.
{% capture c_date %}{{'now' | date: "%m-%d-%Y" }}{% endcapture %}
{% capture n_date %}{{'now' | date: "%s" | plus : 100800 | date: "%m-%d-%Y"}}{% endcapture %}
{% capture n_n_date %}{{'now' | date: "%s" | plus : 201600 | date: "%m-%d-%Y"}}{% endcapture %}
{% capture n_n_n_date %}{{'now' | date: "%s" | plus : 302400 | date: "%m-%d-%Y"}}{% endcapture %}
{% capture c_month %}{{ 'now' | date: "%-m" }}{% endcapture %}
{% capture co_month %}{{ 'now' | date: "%m" }}{% endcapture %}
{% capture c_year %}{{ 'now' | date: "%Y" }}{% endcapture %}
{% capture c_day %}{{ 'now' | date: "%w" }}{% endcapture %}
{% capture nod_curent_month %}{{ 'now' | date: "%-d"}}{% endcapture %}
{% assign n_day = c_day %}
{% assign i = 0 %}
The question is: How can I achieve this ? : "If the current day is Friday, delivery won't be available for Monday and Tuesday."
I am still so new to liquid and spent a lot time on this but now I don't know how to achieve this... first tried to capture %a and added something like {% if c_date == 'Mon' %}
?? <-- Edit 1#: this is the first part but not the solution. What I am missing is after checking the day, showing the div for Mon & Thu.
Edit 2# : here is the link. Click to the calendar icon to see it.
Any help is really appreciated! Thanks for your time :)
Edit 3# : If today is Friday, show a div on Monday and Tuesday at the calendar. (To show that delivery on those days are unavailable) How can I achieve this with .liquid?
Edit 4# : Still active. Posted almost all my code to this LINK
Edit 5# : This is my if else statement for different availabilities. The second if else part is the one I tried to check if the day is friday. But I couldn't find how to show that div for monday and tuesday. So you can see there is only one line that tries to check the day.
{% if c_date == day %}
<div class="deliveryUnavailable currentDay">
<span class="day">{{ nod_curent_month }}</span>
<span class="event"></span>
<span class="deliveryType">Current Day</span>
<span class="deliveryPrice"></span>
</div>
{% else %}
{% capture c_date %}{{ 'now' | date:'%a' }}{% endcapture %}
{% if c_date == 'Fri' %}
<div class="deliveryUnavailable">
<span class="day">{{ nod_curent_month }}</span>
<span class="event"></span>
<span class="deliveryType">Delivery Unavailable.</span>
<span class="deliveryPrice"></span>
</div>
{% else %}
{% if add_sat == n_day %}
<div class="deliveryAvailable" onclick="selectDate('{{ day }}','{{ e_charge }}');">
<span class="day">{{ nod_curent_month }}</span>
<span class="event"></span>
<span class="deliveryType">Saturday Delivery</span>
<span class="deliveryPrice"> + {{ e_charge }} </span>
</div>
{% else %}
{% if n_date == day or off_sun == n_day or off_mon == n_day or off_tue == n_day or off_wed == n_day or off_thur == n_day or off_fri == n_day or off_sat == n_day %}
<div class="deliveryUnavailable">
<span class="day">{{ nod_curent_month }}</span>
<span class="event"></span>
<span class="deliveryType">Delivery Unavailable</span>
<span class="deliveryPrice"></span>
</div>
{% else %}
{% if arr_holiday contains day or add_sun == n_day or add_mon == n_day or add_tue == n_day or add_wed == n_day or add_thur == n_day or add_fri == n_day %}
<div class="deliveryAvailable" onclick="selectDate('{{ day }}','{{ e_charge }}');">
<span class="day">{{ nod_curent_month }}</span>
<span class="event"></span>
<span class="deliveryType">Premium Delivery</span>
<span class="deliveryPrice"> + {{ e_charge }} </span>
</div>
{% else %}
<div class="deliveryAvailable" onclick="selectDate('{{ day }}','0');">
<span class="day">{{ nod_curent_month }}</span>
<span class="event"></span>
<span class="deliveryType">Recommended Delivery Date</span>
<span class="deliveryPrice"></span>
</div>
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
Edit 6# : The first image below is the result when I put 'Wed' to test, which then shows the div with the class currentDay (as the first part of if else st. does) then captures and because the day is Wednesday, it shows the div with the class deliveryUnavailable for ALL the rest of the days. So I need to limit it somehow for only Monday and Tuesday.
The 2nd image shows the result for 'Fri' which only gets the current day - makes the next day unavailable - shows saturday delivery and recommended one.
Edit 7# : The image below shows what I'm trying to achieve. As you see it shows current day, makes the next day unavailable (because of one of the if else st.), sundays are always unavailable (because of another if else), if the current day is friday = makes the following monday and tuesday unavailable.
Upvotes: 1
Views: 1007
Reputation: 11198
{% capture c_date %}{{'now' | date:'%a' }}{% endcapture %}
{% if c_date == 'Mon' %}
on my phone right now, but I think this should do it
Upvotes: 2