Conditionally Show Truemed's PDP Widget
The Product Detail Page (PDP) widget lets customers know—right on the product page—that they might be eligible to pay with their HSA/FSA. The widget should only appear when the product qualifies—not every product is HSA/FSA eligible.
Why this matters
Showing the HSA/FSA badge or widget on ineligible products creates a confusing experience: customers click through to checkout expecting to pay with their benefits, only to find out the item isn’t covered. Conditionally rendering the widget based on real eligibility data keeps the storefront accurate and builds trust.
How the widget works
The widget is a JavaScript bundle served from Truemed’s CDN. Add a placeholder <div> to the
PDP template and load the script tag—the widget self-initializes by finding the placeholder and
injecting the HSA/FSA badge and “Learn more” modal into it.
The eligibility check controls whether the placeholder div is rendered at all. The widget does not need to be called manually.
How to implement
Option 1: Use stored eligibility data (recommended)
The most performant approach is to store each product’s Truemed eligibility status (see Build HSA/FSA-Eligible Collections) and use it to conditionally render the placeholder server-side or at page load.
Option 2: Use the Checkout Method endpoint
For a real-time eligibility check, call
check_truemed_checkout_method
from your server with the item’s SKU and return the result to the frontend. The response
indicates whether Truemed should be shown as a checkout option for that item. This endpoint
evaluates item type only—it does not account for prices, discounts, or additional charges.
Because this call requires your Truemed API credentials, it must never be made directly from the browser.
Server (your backend):
Client (your storefront):
Single-page application (SPA) support
For SPAs where the product page re-renders client-side without a full navigation, call
reloadWidget() after the new product loads to reinitialize the widget:
Configuration options
The placeholder element accepts the following attributes: