I am trying to add a custom CTA button to all the products on a collection page of my store. This CTA pops up a small form. I have added the entire code of this CTA in a new liquid file ‘request-price.liquid’ and calling this liquid file on the ‘main-collection.liquid’ using the below code:
{% for product in collection.products %}
{% render ‘request-price’, product: product %}
{% endfor %}
The button is functioning fine but it reflects with the first product only when I want it to come with all the product cards on a collection page.
Not sure what I am missing in the loop.
Please advise your expert recommendations for this to fix.
Based on the code you provided, it seems that you are rendering the ‘request-price’ liquid file within a loop that iterates over the products in a collection. However, the issue you are facing is that the button is only appearing for the first product and not for all the products on the collection page.
To ensure that the button appears for all products, you can modify your code as follows:
Make sure the ‘request-price.liquid’ file contains the code for the custom CTA button and form.
Open the ‘main-collection.liquid’ file (or the file where you want to display the button) in your theme’s code editor.
{% for product in collection.products %}
{% endfor %}
Locate the section where the product cards are being rendered. It might look something like this:
Inside the product card loop, add the code to render the ‘request-price’ liquid file. It should look like this:
{% for product in collection.products %}
{% render 'request-price', product: product %}
{% endfor %}
Save the changes to the file.
By including the {% render ‘request-price’, product: product %} code within the product card loop, you are instructing Shopify to render the ‘request-price’ liquid file for each product in the collection. This should ensure that the custom CTA button appears for all the products on the collection page.
Make sure to test the changes on your store and adjust the code as needed based on your specific requirements.
To troubleshoot the problem, here are some suggestions:
Verify that the ‘request-price’ snippet is properly defined in your theme. Make sure it is registered correctly and accessible within the appropriate location.
Check if the ‘request-price’ snippet contains the necessary logic to display the price request functionality. Ensure that any required variables or data are correctly referenced and available.
Review the Liquid code within the ‘request-price’ snippet and ensure there are no syntax errors or missing tags.
Check for any error messages or warnings in the console log of your website’s browser developer tools. This can help identify any JavaScript or Liquid errors that might be causing issues with rendering the ‘request-price’ snippet.
If possible, isolate the ‘request-price’ snippet and test it separately to determine if the issue lies within that specific code or if there are other factors affecting its functionality.
If you continue to experience difficulties, it would be helpful to provide more information about the ‘request-price’ snippet and any relevant error messages or unexpected behavior you’re encountering.
Here you can see it. When you click on the “Request Price” button under the first product card, a pop up form comes up. But this form is not come when you click any other button on the same page. All the buttons are managed by the same code as I given in my first message here.