Docschargebeedocs

HomeBillingPaymentsRevRecGrowthReveal
Support

Product Updates


  • Release Notes

Getting Started


  • Overview
  • Chargebee Billing Data Centers
  • Object Relationship Model
  • Understanding Sites
  • Developer Resources
  • Chargebee Tech Glossary
  • Articles and FAQ

Implementing Chargebee


  • Implementation Guide
  • Go-live Checklist
  • Articles and FAQ

AI in Chargebee


  • Chargebee Agents
  • Chargebee Copilot
  • Chargebee MCP Server (Model context protocol)

Product Catalog


  • Product Catalog Overview
  • Coupons
  • Articles and FAQ

Subscriptions


  • Working with Subscriptions
  • Billing
  • Orders
  • Articles and FAQ

Customers


  • Managing Customers
  • Account Hierarchy
  • Email Notifications
  • Branding
  • Configure Multiple Languages
  • Articles and FAQ

Invoices, Credit Notes and Quotes


  • Invoices
  • Credit Notes
  • Quotes [Legacy]
  • Transactions
  • Articles and FAQ

Taxes


  • Overview
  • Configuring Taxes
  • Country-specific Taxes
  • Articles and FAQ

Hosted Capabilities


  • Overview
  • Hosted Checkout
  • Hosted Self-Serve Portal
  • Hosted Pages Features
  • Additional Hosted Pages
  • Payment Components
  • Managing payments with ChargebeeJS
  • Mobile-Optimized Hosted Pages
  • Articles and FAQ

Site Configuration


  • Users & Roles
  • Custom Fields & Metadata
  • Mandatory Fields
  • File Attachments & Comments
  • Advanced Filter Options
  • Multicurrency Pricing
  • Multi-decimal Support
  • Configuring Reason Codes
  • Events and Webhooks
  • API Keys
  • Time Zone
  • Time Machine
  • Transfer Configurations
  • Articles and FAQ

Reports and Analytics


  • RevenueStory
  • Home Dashboard
  • Frequently Asked Questions
  • FAQs for Classic Reports Sunset
  • Articles and FAQ

Integrations


  • Sales
  • Customer Support and Success
  • Finance
  • Tax
  • Marketing
  • Stitch
  • Collaboration
  • Contract Management
  • Order Management
  • Mobile Subscriptions (Legacy)
  • Other Integrations
  • Articles and FAQ

Data Privacy & Security


  • Two Factor Authentication
  • SAML Single Sign-On
  • System for Cross-Domain Identity Management (SCIM)
  • EU-GDPR
  • Consent Management
  • Personal Data Management
  • Compliance Certificates
  • HIPAA Guidelines
  • PCI Recommendations and Integration Types
  • Articles and FAQ

Data Operations


  • Bulk Operations
  • Migration
  • Articles and FAQ
  1. Billing
  2. Integrations
  3. Articles and FAQ
  4. BigCommerce
  1. Billing
  2. Integrations
  3. Articles and FAQ
  4. BigCommerce

How to setup Chargebee checkout with BigCommerce store?

Scope

How to set up Chargebee Checkout with BigCommerce Store?

Summary

You can extract the zip file provided and use the sample code by following the instructions below to set up Chargebee checkout with the Bigcommerce store.

Solution

Setting basic Chargebee checkout in BigCommerce Theme

  • Download the custom theme from this link

  • Extract it and then change the site name intemplates/layout/base.html

  • Replacedata-cb-site="cb-ashik-test" to data-cb-site="example-test"

  • Zip it and upload it to BigCommerce by navigating to Storefront > Theme > Upload theme (If you have an existing theme, delete it and upload)

  • Our theme does not get updated automatically, seems like some cache. To get the latest update just edit any file and save it. Refer to Cache clearing using Edit Theme Files video instructions on how to do that.

    Refer to this link for video instructions

Cache clearing using Edit Theme Files

Go to Themes > Edit theme files then leave space and Save and Apply file.

Refer to this link for video instructions.

What we've done

Assumptions

For this example, we'll be using the Cornerstone-5.1.0 theme (light) however the same thing can be done for other themes also. We just need to do these configs in their equivalent files

Configure Drop-in Script

Get the drop-in script from the Chargebee Admin console and include it intemplates/base.htmlthe file of the theme file

https://www.chargebee.com/checkout-portal-docs/drop-in-tutorial.html#implementation

image

The sample code will look something like this:

<script src="https://js.chargebee.com/v2/chargebee.js" data-cb-site="bc-demo-test"></script>
<!-- replace bc-demo-test with your site name -->
image

Create custom fields in your product

Create custom fields in your BigCommerce product that we can use to map the associated Chargebee product id.

In our example, we'll be using chargebee_plan_id (we can name it whatever we want, but make sure to make necessary changes in code also

Product details page

Add this intemplates/components/products/add-to-cart.html page. It'll check if we've chargebee_plan_id custom field for that particular product if so it'll use Chargebee checkout if not then the BigCommerce cart will kick in.

The following details are sent from the product details page.

  • plan Id

  • plan quantity (reactive)

{{inject 'product' product}}

<script>
    var bcJsContext = JSON.parse({{ jsContext }});
</script>

<script>
    function cbCheckoutInit(event) {
        let cbInstance = Chargebee.getInstance();
        let cart = cbInstance.getCart();
        let [planIdCustomField] = bcJsContext.product.custom_fields.filter(field => field.name === "chargebee_plan_id");
        if (planIdCustomField) {
            document.getElementById("form-action-addToCart").value = 'Subscribe';
        }
        document.getElementById("form-action-addToCart").addEventListener("click", function (event) {
            if (planIdCustomField) {
                event.preventDefault();
                let productQty = document.querySelector('.form-input--incrementTotal').value;
                let product = cbInstance.initializeProduct(planIdCustomField.value);
                product.isItemsModel = true; // Set this flag to true only if the site is Latest Product Catalog
                product.setPlanQuantity(productQty);
                cart.replaceProduct(product);
                cart.proceedToCheckout();
            }
        });
    }

    let cbInitCheckerIntervalId;
    cbInitCheckerIntervalId = setInterval(() => {
        if (Chargebee && Chargebee.inited) {
            clearInterval(cbInitCheckerIntervalId);
            cbCheckoutInit();
        }
    }, 100);
</script>

image

Listing

card.html

Pass custom_fields property of product to the card from where ever it's called

Like this:

// top.html
  {{>components/products/card settings=../settings theme_settings=../theme_settings customer=../customer event="list" position=(add @index 1) custom_fields=this.custom_fields}}
// Do the same in featured.html, grid.html, related.html, carousel.html as well.

top.html

image

Refer to this link for video instructions

Similarly, do it for

  • components/products/featured.html

  • components/products/grid.html

  • components/products/related.html

  • components/products/carousel.html

Card.html

In card.html, replace the #if add_to_cart_url block with the following sample code.

Legacy Product Catalog

  {{#each custom_fields}}
    {{#if this.name '===' 'chargebee_plan_id'}}
        {{assignVar "chargebeePlanId" this.value}}
        <a href="javascript:void(0)" 
           data-cb-type="checkout" 
           data-cb-plan-id="{{this.value}}"  
           class="button button--small card-figcaption-button">
            Subscribe
        </a>
    {{else}}
        {{#if add_to_cart_url}}
            <a href="{{add_to_cart_url}}" 
               data-event-type="product-click" 
               data-button-type="add-cart"
               class="button button--small card-figcaption-button">
                {{lang 'products.add_to_cart'}}
            </a>
            <span class="product-status-message aria-description--hidden">
                {{lang 'category.add_cart_announcement'}}
            </span>
        {{/if}}
    {{/if}}
{{/each}}

{{#unless custom_fields}}
    {{#if add_to_cart_url}}
        <a href="{{add_to_cart_url}}" 
           data-event-type="product-click" 
           data-button-type="add-cart" 
           class="button button--small card-figcaption-button">
            {{lang 'products.add_to_cart'}}
        </a>
        <span class="product-status-message aria-description--hidden">
            {{lang 'category.add_cart_announcement'}}
        </span>
    {{/if}}
{{/unless}}

Latest Product Catalog

The only change here we're replacing data-cb-plan-id with data-cb-item-0

{{#each custom_fields}}
    {{#if this.name '===' 'chargebee_plan_id'}}
        {{assignVar "chargebeePlanId" this.value}}
        <a href="javascript:void(0)" 
           data-cb-type="checkout" 
           data-cb-item-0="{{this.value}}"  
           class="button button--small card-figcaption-button">
           Subscribe
        </a>
    {{else}}
        {{#if add_to_cart_url}}
            <a href="{{add_to_cart_url}}" 
               data-event-type="product-click" 
               data-button-type="add-cart"
               class="button button--small card-figcaption-button">
               {{lang 'products.add_to_cart'}}
            </a>
            <span class="product-status-message aria-description--hidden">
                {{lang 'category.add_cart_announcement'}}
            </span>
        {{/if}}
    {{/if}}
{{/each}}

{{#unless custom_fields}}
    {{#if add_to_cart_url}}
        <a href="{{add_to_cart_url}}" 
           data-event-type="product-click" 
           data-button-type="add-cart" 
           class="button button--small card-figcaption-button">
           {{lang 'products.add_to_cart'}}
        </a>
        <span class="product-status-message aria-description--hidden">
            {{lang 'category.add_cart_announcement'}}
        </span>
    {{/if}}
{{/unless}}

Refer to this link for video instructions

Applying theme

And make sure to apply the uploaded theme. Alternatively, if you're using Stencil based theme then you can use CLI to easily upload the theme and the development work locally

https://developer.bigcommerce.com/docs/storefront/stencil

image

Limitations

  • We do not support Multi subscription support yet hence the end user will be able to subscribe to only one product (subscription) at a time.

  • This customization is not straightforward and needs a developer to make these changes.

References

https://developer.bigcommerce.com/docs/storefront/stencil/themes/context/handlebars-reference#contains

Related Articles

How does Chargebee and BigCommerce interact?

Was this article helpful?