Need help to create custom variants button in dawn theme product page same as below shared s.s.
Hey @TheLivingCo ,
To achieve a similar custom variant selection layout in the Dawn theme on your product page, you’ll need to modify the product template and use custom CSS to style the buttons. Here are the steps to get started:
Follow these steps:
-
Online store > Theme > Edit Code
-
Open the main-product.liquid (or similar product template file) in the Section folder.
-
Locate the area where product variants are rendered. By default, this might be a dropdown or a button layout. You’ll replace it with a custom button-based layout.
Create Custom Buttons for Variants:
-
Replace the default variant selection code with custom buttons that render each variant as a separate button.
-
Use a for loop to iterate through the variants and display each one as a button with relevant details like price, discount, and package information.
Here’s a sample snippet to create buttons for each variant:
{% for variant in product.variants %}
{% endfor %}
Add JavaScript for Variant Selection:
Add JavaScript to handle variant selection when a user clicks a button. This code will set the selected variant ID on the form.
Style the Variant Buttons:
Use custom CSS to style the variant buttons to match the look in the screenshot. You can add the following CSS in your base.css or theme.css file.
.variant-options {
display: flex;
gap: 10px;
margin-top: 20px;
}
.variant-button {
padding: 10px;
border: 1px solid #ddd;
border-radius: 8px;
text-align: center;
cursor: pointer;
background-color: #fff;
transition: background-color 0.3s;
}
.variant-button.active, .variant-button:hover {
background-color: #ffe4e1;
}
.variant-title {
font-weight: bold;
font-size: 16px;
}
.variant-price {
font-size: 14px;
color: #ff6a6a;
}
.variant-discount {
font-size: 12px;
color: #999;
}
.variant-percentage {
font-size: 14px;
color: #ff6a6a;
font-weight: bold;
}
Test and Adjust:
-Preview your product page to ensure the buttons are styled correctly and functional.
-Adjust the styles as needed to achieve the exact look shown in your screenshot.
Let me know if you need further assistance with any of these steps or with fine-tuning the design.
If I was able to help you, please don’t forget to Like and mark it as the Solution!
Best Regard,
Rajat Sharma
Hi Rajweb,
thank you for your help, can you help me about where to add this codes
Certainly! Here’s a step-by-step guide on where exactly to place each part of the code in your Dawn theme:
Steps 1. Add Custom Variant Buttons to the Product Template:
-
Go to Shopify Admin:
Navigate to Online Store > Themes. -
Edit Code:
Find the Dawn theme, click on Actions > Edit Code. -
Open Product Template:
In the code editor, go to the Sections folder and look for a file named main-product.liquid or product-template.liquid . Open this file. -
Locate the Variant Selector:
In the file, find the section where variants are displayed. This is usually a
Thank you for your help but still i’m not able to do that. can you help me?
Could you please send me an email so we can discuss this further? I’d be happy to go over the details with you.
