Shopify Guides

Boost Conversions: How to Implement Custom Star Ratings in Shopify OS 2.0

Hey everyone, it's your Shopify migration expert here at Shopping Cart Mover. I was just digging through the community forums, and a question from saqlain1 caught my eye: "Need star rating custom code." It's a classic – how do you get those eye-catching product star ratings onto your Shopify store, exactly how you want them?

Star ratings are more than just pretty icons; they're vital social proof that can significantly boost buyer confidence and conversion rates. When a potential customer sees a product with a solid 4.7-star rating and thousands of reviews, it instantly builds trust. That's why getting them right, both functionally and aesthetically, is so important for any thriving e-commerce business.

Shopify theme code editor showing how to add a new custom section for star ratings.
Shopify theme code editor showing how to add a new custom section for star ratings.

The Power of Custom Star Ratings: Beyond Standard Apps

While numerous Shopify apps offer star rating functionalities, relying solely on them can sometimes lead to limitations in design flexibility, potential performance overhead from extra scripts, or even recurring subscription costs. saqlain1's query for "custom code" highlights a desire for granular control, and the Shopify community truly delivered.

Two helpful members, oscprofessional and ajaycodewiz, stepped up with fantastic Liquid and CSS solutions for creating a fully customizable Shopify OS 2.0 section. This approach is ideal for store owners who want complete control over every aspect of their star ratings, ensuring they perfectly match their brand's aesthetic and perform efficiently.

Why Opt for a Custom Code Solution?

  • Unmatched Customization: Tailor colors, sizes, spacing, alignment, and even the star icon itself to perfectly match your brand.
  • Performance Benefits: Avoid the extra JavaScript and CSS files that come with many third-party apps, potentially leading to faster page load times.
  • Seamless Integration: Integrate the rating display directly into your theme's structure as a native OS 2.0 section, making it easy to add to any page or template.
  • Long-Term Stability: Less reliance on external app updates or compatibility issues.

Building a Custom Star Rating Section with Code: A Step-by-Step Guide

Let's walk through how you can implement a robust custom star rating section, using ajaycodewiz's detailed solution as a prime example. This approach uses SVG stars, which gives you crisp, scalable icons at any size, ensuring your ratings look sharp on any device.

Implementation Steps:

  1. Access Your Theme Code:
    • In your Shopify admin, navigate to Online Store > Themes.
    • Find your current theme (e.g., "Kalles" as tested in the forum) and click the button, then select Edit code.
  2. Create a New Section:
    • Under the Sections directory, click Add a new section.
    • Name it custom-star-rating (it will create a file named custom-star-rating.liquid).
    • Delete any starter content that Shopify automatically generates for this new section.
  3. Paste the Custom Code:
    • Copy the entire code block provided by ajaycodewiz (or oscprofessional if you prefer Unicode stars and slightly different settings) from the forum thread.
    • Paste it into your newly created custom-star-rating.liquid file.
    • Click Save.

Understanding the Code: Liquid, CSS, and Schema

The provided code is a powerful example of a Shopify OS 2.0 section, combining Liquid for logic, CSS for styling, and a Schema for user-friendly settings in the theme editor.

Liquid Logic (
{%- liquid ... %}{%- capture stars -%} ... {%- endcapture -%}
):

This part calculates the rating percentage, ensuring partial stars are rendered correctly. It dynamically generates SVG star icons, capturing them in a variable for reuse. The SVG path for the star is embedded directly, making it highly efficient.

HTML Structure (
...
):

The core HTML uses `div` elements to structure the stars and text. Key elements include:

  • .csr__stars-base: Renders the full set of empty stars.
  • .csr__stars-fill: Renders the filled stars, which are then clipped to the calculated percentage, creating the partial star effect.
  • .csr__num and .csr__count: Display the numerical rating and review count.

CSS Styling (
):

The CSS uses custom properties (--csr-fill, --csr-empty, etc.) defined in the Liquid section. This allows for dynamic styling directly from your theme settings. It handles the alignment, spacing, colors, and the crucial overlapping of filled and empty stars to create the partial rating visual.

Schema (
{% schema %} ... {% endschema %}
):

This is where the magic happens for non-coders. The schema defines all the customizable settings that will appear in your Shopify Theme Editor, such as:

  • Rating: A range slider (0-5, with 0.1 steps) to set the average rating.
  • Number of Stars: Control the total number of stars displayed (e.g., 5, 7, 10).
  • Review Count Text: Fields for the numerical count and a custom label (e.g., "4,777 Aggregated Reviews*").
  • Star Colors & Size: Color pickers for filled and empty stars, and sliders for star size and gap.
  • Text Settings: Color and size for the rating and review count text.
  • Layout: Options for alignment (left, center, right), background color, padding, and corner radius.

Adding the Custom Star Rating Section to Your Store

Once you've saved the custom-star-rating.liquid section:

  1. Go back to your Shopify admin and navigate to Online Store > Themes > Customize (to open the Theme Editor).
  2. On any page (e.g., homepage, product page), click Add section in the left sidebar.
  3. Scroll down and select Custom star rating (or whatever name you gave it in the schema).
  4. Now, you can use the settings in the sidebar to adjust the rating, colors, sizes, and text to your heart's content!

Integrating with Review Apps and Best Practices

While this custom section provides a beautiful display, remember it's primarily for presentation. For collecting actual customer reviews, you'll still want a robust review app like Shopify Product Reviews, Loox, Yotpo, or Judge.me. You can then manually input the aggregated rating and review count into your custom section's settings for a dynamic, yet controlled, display.

Tips for Maximizing Impact:

  • Strategic Placement: Display ratings prominently on product pages, collection pages, and even your homepage to build immediate trust.
  • Encourage Reviews: Actively solicit reviews from customers post-purchase.
  • Maintain Authenticity: Ensure your displayed ratings accurately reflect customer feedback.
  • Mobile Responsiveness: The provided code includes basic media queries, but always test on various devices.

Conclusion

Implementing a custom star rating section on your Shopify OS 2.0 store gives you unparalleled control over a crucial element of social proof. By leveraging the power of Liquid, CSS, and Shopify's flexible section architecture, you can create a truly unique and high-performing display that boosts buyer confidence and drives conversions, all without the bloat of unnecessary apps.

If you're looking to build a new store or enhance your current e-commerce presence, starting with Shopify offers unparalleled flexibility and a robust platform. And if you need expert assistance with complex Shopify customizations, theme development, or even migrating your entire store, don't hesitate to reach out to the specialists at Shopping Cart Mover. We're here to help you make your e-commerce vision a reality!

Share:

Use cases

Explore use cases

Agencies, store owners, enterprise — find the migration path that fits.

Explore use cases