カートに追加のボタンの飛び先を変更したい

現在、商品ページの「カートに追加」を押下すると、チェックアウト画面に遷移します。

これをカートページにと飛ぶように変更したいと考えております。

ご教示いただけますと幸いです。

よろしくお願いいたします。

▽product-form.liquid

{% if type == 'block' and block.settings.show_payment_button %}
    {% assign show_payment_button = true %}
  {% elsif section.settings.show_payment_button %}
    {% assign show_payment_button = true %}
  {% elsif show_payment_button_quickshop %}
    {% assign show_payment_button = true %}
  {% else %}
    {% assign show_payment_button = false %}
  {% endif %}

  {% assign variant = product.selected_or_first_available_variant %}

  
    {% form 'product', product %}

    {% if product.available %}
      {% if settings.display_inventory_left %}
        

          {% if variant.inventory_management != blank and variant.inventory_quantity > 0 %}
            {% capture items_left_text %}
              {% if variant.inventory_quantity == 1 %}
                {{ 'products.product.items_left_count.one' | t }}
              {% else %}
                {{ 'products.product.items_left_count.other' | t }}
              {% endif %}
            {% endcapture %}
            {% if variant.inventory_quantity <= settings.inventory_threshold %}
              {{ variant.inventory_quantity }} {{ items_left_text }}
            {% endif %}
          {% endif %}
        

      {% endif %}
    {% endif %}

    {% if product.options.size > 1 %}
      
        
      

    {% elsif product.options.size == 1 and product.variants.size > 1 or product.options.size == 1 and product.options[0] != "Title" %}
      
        
        
      

    {% else %}
      
    {% endif %}

    {% if settings.product_form_style == "swatches" and product.variants.size > 1 or settings.product_form_style == "swatches" and product.options[0] != "Title" %}
      

        {% for option in product.options %}
          {% render 'product-swatch',
                  option: option,
                  product: product
          %}
        {% endfor %}
      

    {% endif %}

    
      {% if settings.display_product_quantity and product.available %}
        

		  
          

            
            
            
            
          

        

      {% endif %}
      
        

          {% if settings.cart_action == 'reload_page' %}
            
          {% elsif settings.cart_action == 'redirect_checkout' %}
            
          {% endif %}

          {% capture add_to_cart_label %}{% if collection_handles contains 'pre-order' %}{{ 'collections.general.pre_order' | t }}{% else %}{% if product.available %}{{ 'products.product.add_to_cart' | t }}{% else %}SOLD OUT{% endif %}{% endif %}{% endcapture %}

          

            
            {% if show_payment_button %}
              {{ form | payment_button }}
            {% endif %}
          

        

      

    

  {% endform %}

質問者様と同じテーマを使用しているわけではないので、

十分な調査ができたとは言い難いのですが、

下記のコードが怪しそうです。

{% if settings.cart_action == 'reload_page' %}
            
          {% elsif settings.cart_action == 'redirect_checkout' %}
            
          {% endif %}

下記は、Shopifyの海外コミュニティに投稿された質問です。

https://community.shopify.com/c/shopify-discussions/solved-how-can-i-skip-the-cart-and-go-straight-to-checkout/td-p/331597

質問者様とは逆に、カートをスキップして購入画面に行きたいという質問ですね。

その方法として、下記のコードを挿入する、と言っています。


同様のコードが質問者様のテンプレートにもあるようです。

解決策としては、下記いずれかになるかと思います。

  1. 該当コードを削除する
  2. テンプレート全体を"settings.cart_action"で検索し、その値が"redirect_checkout"になっている場合、その値を空値にする。もし、カート追加と同時に、カートに遷移させず、商品情報ページに止まらせたい場合は、"settings.cart_action"を"reload_page"に変更すると良いです。

2の方が挙動をコントロールできるのでお勧めですが、

よく分からないという場合は、

下記を全て削除し、

{% if settings.cart_action == 'reload_page' %}
            
          {% elsif settings.cart_action == 'redirect_checkout' %}
            
          {% endif %}

カート追加と同時に、カートに遷移させたい場合はそれで完了。

カート追加時には、カートに遷移させたくない場合には、


を削除したコードの代わりに設置すると良いです。

このコードについては、同じく海外のコミュニティで言及されていますのでご興味あればご確認ください。

https://community.shopify.com/c/shopify-scripts/add-to-cart-button-redirects-to-cart-page-and-changes-web-page/td-p/1101040

ご参考までに。

(キュー田辺)

1 Like

ご丁寧にありがとうございます!上記で解決しました!

ベストソリューションに選ばせていただきます!