ある特定の予約商品に販売期間前はカート機能をOFF、販売期間中はON、販売期間後はOFFといったものを商品メタフィールドを使って設定しています。
機能自体は正常に動作するのですが、「カートに入れる」ボタンの文字が販売期間前のOFFの時は「COMING SOON」、販売期間後のOFFの時は「FINISHED」と表示したいのですが、前も後もファーストセレクトではちゃんと表示されているものの、バリエーションの選択を変えると、デフォルト設定の「SOLD OUT」に切り替わってしまいます。ページ更新すれば「COMING SOON」や「FINISHED」に戻ります。
当方、Dawnテーマを使用しています。
下記、記述しているコードになります。
原因おわかりになりますでしょうか?
ぜひご教授いただければと思い、質問させていただきます。
何卒宜しくお願い致します。
{%- assign saleStartDate = product.metafields.custom.saleStartDate | date: “%s” -%}
{%- assign saleEndDate = product.metafields.custom.saleEndDate | date: “%s” -%}
{%- assign saleStartDateValue = product.metafields.custom.saleStartDate.value -%}
{%- assign saleEndDateValue = product.metafields.custom.saleEndDate.value -%}
{%- assign nowTime = “now” | date: “%s” -%}
{%- assign startTimeLag = nowTime | minus: saleStartDate -%}
{%- assign endTimeLag = nowTime | minus: saleEndDate -%}
{%- assign stringNameAdd = ‘’ -%}
{%- assign stringBuy = ‘’ -%}
{%- if saleStartDateValue == null and saleEndDateValue == null -%}
{%- assign stringNameAdd = ‘name=“add”’ -%}
{%- assign stringBuy = ‘buy’ -%}
{%- elsif startTimeLag >= 0 and saleEndDateValue == null -%}
{%- assign stringNameAdd = ‘name=“add”’ -%}
{%- assign stringBuy = ‘buy’ -%}
{%- elsif saleStartDateValue == null and endTimeLag <= 0 -%}
{%- assign stringNameAdd = ‘name=“add”’ -%}
{%- assign stringBuy = ‘buy’ -%}
{%- elsif startTimeLag >= 0 and endTimeLag <= 0 -%}
{%- assign stringNameAdd = ‘name=“add”’ -%}
{%- assign stringBuy = ‘buy’ -%}
{%- endif -%}
<button
id=“ProductSubmitButton-{{ section_id }}”
type=“submit”
{{ stringNameAdd }}
class=“product-form__submit button button–full-width {% if show_dynamic_checkout and product.selling_plan_groups == empty %}button–secondary{% else %}button–primary{% endif %}”
{%- if stringBuy != ‘buy’ or product.selected_or_first_available_variant.available == false
or quantity_rule_soldout
or product.selected_or_first_available_variant == null
-%}
disabled
{%- endif -%}