Rendering a checkout button
Learn how to configure a checkout button that can be used to create a Prebuilt Checkout modal
Last updated
Learn how to configure a checkout button that can be used to create a Prebuilt Checkout modal
Last updated
The exposes renderButton()
, which allows you to define a checkout button's location, style, and text. It can also hide existing buttons and initiate the creation of a .
The function accepts two parameters, a and .
The required button container represents the id
for the in which you want to render your checkout button.
In button options, you can:
Define how you'd like to handle:
The style
object can be used to define the visual appearance of a checkout button:
backgroundColor
: Sets the background color
borderRadius
: Determines the roundness of the button's corners
color
: Sets the color of the text
fontSize
: Sets the font size of the text
fontWeight
: Sets the font weight of the text
fontFamily
: Specifies the button's font family. If the browser doesn't support the first font, it moves through the list, from left to right, looking for one it does.
':hover'
: This object contains a nested color
property which determines the color of the button when it's hovered over.
The buttonText
allows you to customize the characters displayed on the button. The default value is Check out
.
In the example, '.cart-actions > a.button'
and '.previewCartAction-checkout > a.button'
target elements that have a class
value of "button"
and are descendants of elements with classes of "cart-actions"
and "previewCartAction-checkout"
, respectively.
The hiddenElement
array represents one or more strings that you want to locate and then hide before rendering the checkout button. This allows you to conceal add to cart, cart preview, and similar buttons that might exist on the page.
The afterRender
boolean determines whether or not the gets dynamically added to the .
The onInit
property can be assigned a callback method, which accepts , that executes when the checkout button first renders.
The onClick
property can be assigned a callback method, which accepts , that executes when the user clicks the checkout button.
In most cases, to handle this event, you'll define an asynchronous function that creates a and then passes its identifier to .
For details, refer to on the page.
The onCancel
property can be assigned a callback method that executes when users close the before completing the purchase.
The property in the also allows you to listen for modal closed events.