Skip to main content
SureCart provides multiple ways to add items to the cart programmatically:
  1. URL Parameters - Redirect users to checkout with pre-filled line items
  2. Shortcodes - Use built-in shortcodes for add-to-cart buttons
  3. 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 with line_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

Parameters
Shortcode Parameters

Buy Button with Line Items

Multiple Line Items

Using Shortcodes in PHP

You can render shortcodes programmatically in PHP using WordPress’s do_shortcode function.
For buy buttons with multiple line items:

Checkout Form Customization

Add custom fields, checkboxes, or content to checkout forms using the render_block filter. This example walks you through adding a terms checkbox with server-side validation.
1

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'].
2

Add server-side validation

Validate custom fields using the surecart/checkout/validate filter. Return errors to prevent checkout submission.
See Checkout Hooks for more validation examples.

Checkout Block Names


Cart Hooks

Customize cart icon, visibility, and behavior.

Checkout Hooks

Hook into checkout events and customize validation.