Add a shipping rates calculator to your Shopify cart

Hura Product Showcase Builder

You can add a shipping rates calculator to your cart page that lets customers estimate their shipping costs before they proceed to the checkout page.

The shipping rates calculator displays your shipping rates on the cart page of your store. If a customer is logged in, then the calculator uses the customer’s default shipping address to estimate shipping rates. The shipping rates calculator works with carrier-calculated rates, manual rates, or a combination of the two.

Step 1: Editing your theme code to add the shipping calculator

    1. From your Shopify admin, go to Online Store > Themes.
    2. Find the theme you want to edit, and then click Actions > Edit code.
    3. In the Assets directory, click vendor.js. If your theme doesn’t have a vendor.js file, then click theme.js instead.
    4. To the very bottom of vendor.js, paste this code hosted on GitHub. If you are editing theme.js instead, then paste the same code snippet at the very top of the file.
    5. Click Save.
    6. In the Assets directory, click theme.js. To the very bottom of the file, paste the following code:
    7. Click Save.
    8. In the Snippets directory, click Add a new snippet.
    9. Name your new snippet shipping-calculator, and click Create snippet:

      Your new snippet will open in the code editor.
    10. Into your new shipping-calculator.liquid snippet, paste this code hosted on GitHub.
    11. Click Save.
    12. In the Sections directory, click cart-template.liquid. If your theme doesn’t have a cart-template.liquid file, then, in the Templates directory, click cart.liquid.
    13. Find the closing </form> tag. On a new line right above the closing </form> tag, paste the following code:
    14. At the very bottom of the file, paste the following code:
    15. Click Save.
    16. In the Config directory, click settings_schema.json. The file will open in the code editor.
    17. Near the very bottom of the file, paste the following code before the last square bracket ] and after the last curly bracket } – make sure to include that first comma , since you’re modifying a JSON data structure:

Step 2: Configuring your shipping rates calculator

You can now edit the settings for your shipping rates calculator from the theme editor.

  1. Go to the theme editor.
  2. Under Theme settings, click Shipping Rates Calculator to view and edit the calculator settings.
    You can configure the following settings:

      • Show the shipping calculator? – set this to Yes to display the shipping rates calculator on your cart page, or No to hide it
      • Heading text – enter the text that will be displayed above your shipping rates calculator
      • Default country selection – choose which country will be selected by default
      • Submit button label – enter the text that will be shown on the submit button.

Step 3: Editing the HTML or CSS of the calculator

You can edit the HTML code for your shipping rates calculator to make more advanced customizations.

  1. From your Shopify admin, go to Online Store > Themes.
  2. Find the theme you want to edit, and then click Actions > Edit code.
  3. In the Snippets directory, click shipping-calculator.liquid.
  4. Edit the code as needed. You can add new classes and move the existing HTML elements around in the file to suit your needs.
  5. Click Save.

If you want to change the appearance of your shipping rates calculator, then you can add some CSS to your theme stylesheet.

  1. From your Shopify admin, go to Online Store > Themes.
  2. Find the theme you want to edit, and then click Actions > Edit code.
  3. In the Assets directory, click theme.scss.liquid.
  4. At the very bottom of the file, add either the contents of this CSS file, or your own custom CSS code.
  5. Click Save.

DEMO

Hura Theme Blocks

You may also like...

2 Responses

  1. Tori says:

    this ruined my whole front page
    followed the instructions to a tee and the cart worked but front page would never load just showed a loading circle

  2. Lawrence says:

    i installed this code for the shipping calculator

    all works fine and it appears on the cart – but nothing happens when i try CALCULATE SHIPPING ?

    the button does not do anything – please help ?

Leave a Reply

Your email address will not be published. Required fields are marked *