- URL Parameters - Redirect users to checkout with pre-filled line items
- Shortcodes - Use built-in shortcodes for add-to-cart buttons
- Checkout Form Customization - Add custom fields, checkboxes, or content
For a complete reference of available hooks, see the Cart
Hooks and Checkout
Hooks documentation.
URL Parameters
The most straightforward way to add items to cart is by redirecting users to the checkout page withline_items query parameters.
Basic Example
Multiple Items
With Coupon Code
With Product Variant
Shortcodes
SureCart provides built-in shortcodes for adding products to cart.Add to Cart Button
Buy Button with Line Items
Multiple Line Items
Using Shortcodes in PHP
You can render shortcodes programmatically in PHP using WordPress’sdo_shortcode function.
Checkout Form Customization
Add custom fields, checkboxes, or content to checkout forms using therender_block filter. This example walks you through adding a terms checkbox with server-side validation.
Add custom content before the submit button
Use the
render_block filter to inject HTML before any checkout block. Target the block by checking $block['blockName'].Add server-side validation
Validate custom fields using the See Checkout Hooks for more validation examples.
surecart/checkout/validate filter. Return errors to prevent checkout submission.Checkout Block Names
| Block Name | Description |
|---|---|
surecart/submit | Submit/Pay button |
surecart/email | Email field |
surecart/name | Full name field |
surecart/first-name | First name field |
surecart/last-name | Last name field |
surecart/phone | Phone number field |
surecart/address | Address fields |
surecart/payment | Payment method selection |
surecart/coupon | Coupon code field |
surecart/line-items | Order line items |
surecart/totals | Order totals summary |