Marketing opt-in at SureCart checkout: working demo (ticket 1524046)
SureCart has no built in “marketing consent” setting. The supported way to collect an opt-in at checkout is the Checkbox block, which is exactly the workaround you already found. Your checkbox is correct. The part that breaks is what happens after the order, and this page shows why and how to fix it.
Everything below runs on a live SureCart 4.6.4 store in test mode.
Step 1. Buy the test product
The store uses the Test Processor, so no card details are needed. Enter any email and name, tick or leave the opt-in box, then press Purchase.
Step 2. Come back here and reload
The four panels below are fetched live from the SureCart API using your completed order.
1. What the checkbox stored on the checkout
The Checkbox block writes its value into checkout.metadata. Consent on this order: not given
{
"page_id": "753",
"page_url": "https://sure.ivacode.com/popup-text-fixed-1546907/"
}2. What the order webhook actually sends
This is the payload behind the SureCart triggers in Zapier and Pabbly. Note that checkout is only an ID, so there is no metadata anywhere in it. This is why the opt-in never arrives.
{
"id": "3f704223-d18c-46fc-ab8f-359b621caa32",
"object": "order",
"live_mode": false,
"number": "TEST-0195",
"order_type": "checkout",
"status": "paid",
"checkout": "47c0f8e1-0673-479e-8ef8-87a5dc5fa80d"
}3. Fix A - same order, re-fetched with expand[]=checkout
Add one API-request step in Pabbly or Zapier and the opt-in is right there. No code on the site.
{
"id": "3f704223-d18c-46fc-ab8f-359b621caa32",
"number": "TEST-0195",
"checkout": {
"id": "47c0f8e1-0673-479e-8ef8-87a5dc5fa80d",
"email": "popup.demo.927243.1546907@example.com",
"name": "Popup Demo Buyer",
"metadata": {
"page_id": "753",
"page_url": "https://sure.ivacode.com/popup-text-fixed-1546907/"
}
}
}4. Fix B - what the bridge snippet forwarded to the catch hook
One flat payload, delivered the moment the order is confirmed, with an explicit yes or no. HTTP response from the catch hook: 200
{
"event": "surecart_checkout_confirmed",
"checkout_id": "47c0f8e1-0673-479e-8ef8-87a5dc5fa80d",
"order_id": "3f704223-d18c-46fc-ab8f-359b621caa32",
"email": "popup.demo.927243.1546907@example.com",
"first_name": "Popup",
"last_name": "Demo Buyer",
"marketing_consent": "no",
"consented_at": null,
"consent_ip": null,
"raw_metadata": {
"page_id": "753",
"page_url": "https://sure.ivacode.com/popup-text-fixed-1546907/"
}
}The important gotcha
When the box is left unticked, SureCart does not store marketing_consent: no. The key is not stored at all. Browsers never submit an unchecked checkbox, so the field simply never reaches the order.
That means a Pabbly or Zapier filter set to “marketing_consent equals no” will never match, and a filter set to “marketing_consent exists” is the only one that behaves. Run the demo twice, once ticked and once unticked, and compare panel 1.
Fix A – no code, stays inside Pabbly or Zapier
Keep your existing SureCart trigger, then add one API request step before your Flodesk or SureContact step:
Method: GET
URL: https://api.surecart.com/v1/orders/{{order_id_from_trigger}}?expand[]=checkout
Header: Authorization: Bearer YOUR_SURECART_API_TOKEN
The response contains checkout.metadata.marketing_consent. Add a filter step that only continues when that field exists, then send the contact to Flodesk or SureContact. Panel 3 above is that exact call.
Fix B – one snippet, no extra automation step
This runs on the site and posts a clean flat payload straight to your Pabbly or Zapier catch hook, with an explicit yes or no. Panel 4 above is the payload it actually delivered.
add_action( 'surecart/checkout_confirmed', function ( $checkout ) {
$metadata = json_decode( wp_json_encode( $checkout->metadata ?? array() ), true );
$consent = ! empty( $metadata['marketing_consent'] );
wp_remote_post( 'YOUR_CATCH_HOOK_URL', array(
'timeout' => 15,
'headers' => array( 'Content-Type' => 'application/json' ),
'body' => wp_json_encode( array(
'email' => $checkout->email,
'first_name' => $checkout->first_name,
'last_name' => $checkout->last_name,
'marketing_consent' => $consent ? 'yes' : 'no',
'consented_at' => $consent ? current_time( 'mysql' ) : null,
) ),
) );
}, 10, 1 );
How to set up the checkbox itself
SureCart > Custom Forms > edit your checkout form, add the Checkbox block above the Purchase button, then in the block sidebar set:
- Name:
marketing_consent(this becomes the metadata key) - Value:
yes - Required: off, and Checked by default: off (consent has to be an active choice)