Docs

Customization RecipesNew

3 min readUpdated November 24, 2026

Copy-and-paste snippets for the most common ways to adjust WP Smart Consent: what gets sent, where it goes, and how the checkbox behaves. Each recipe uses a public hook from the Developer API, which has the full parameter details.

Where to put these snippets#

Put snippets in a small custom plugin or a must-use plugin (a .php file in wp-content/mu-plugins/). A code-snippets plugin works too. Avoid the theme’s functions.php if you might change themes.

Tip

Most recipes need no function_exists() check: if WP Smart Consent is deactivated, its hooks simply never run.

Sending data to CRMs#

Add the order currency to every WooCommerce opt-in#

add_filter( 'wpsc_checkout_collected_data', function ( $billing, $slug, $order ) {
    if ( in_array( $slug, [ 'woo_block', 'woo_shc' ], true ) && $order ) {
        $billing['currency'] = $order->get_currency();
    }
    return $billing;
}, 10, 3 );

Then add a row with source key currency on your CRM’s Custom fields tab. The same filter works for SureCart (surecart), FluentCart (fluent_cart), Easy Digital Downloads (edd) and GiveWP (givewp).

Calculate a value with your own code#

On WP Smart Consent → Data fields, add a field with the slug customer_tier and the source PHP hook, then:

add_filter( 'wpsc_field_customer_tier', function ( $value, $billing, $order ) {
    if ( $order instanceof WC_Order && $order->get_customer_id() ) {
        return wc_get_customer_order_count( $order->get_customer_id() ) > 5 ? 'loyal' : 'new';
    }
    return $value;
}, 10, 3 );

customer_tier now appears in every CRM’s Field mapping and every webhook’s fields.

Send contacts to a different Mailchimp audience by country#

add_filter( 'wpsc_mailchimp_list_ids', function ( $list_ids, $order, $billing ) {
    if ( in_array( $billing['country'] ?? '', [ 'DE', 'AT', 'CH' ], true ) ) {
        return [ 'dach_audience_id' ];
    }
    return $list_ids;
}, 10, 3 );

Every cloud CRM has the same filter: replace mailchimp with brevo, klaviyo, kit and so on.

Tag buyers differently from newsletter signups#

add_filter( 'wpsc_mailchimp_tags', function ( $tags, $order, $billing ) {
    $tags[] = $order ? 'customer' : 'lead';
    return array_unique( $tags );
}, 10, 3 );

$order is the order object for checkouts and null for forms.

Don’t send test orders to a CRM#

add_filter( 'wpsc_klaviyo_contact', function ( $contact ) {
    if ( str_ends_with( $contact['email'], '@example.com' ) ) {
        return []; // skip this CRM for this contact
    }
    return $contact;
} );

The contact is still logged; only this CRM is skipped.

Map country names your forms use#

add_filter( 'wpsc_normalize_country', function ( $code, $value ) {
    $aliases = [ 'uk' => 'GB', 'england' => 'GB', 'holland' => 'NL' ];
    return $aliases[ strtolower( trim( $value ) ) ] ?? $code;
}, 10, 2 );

Runs only when WooCommerce, Gravity Forms and WP Smart Consent’s own country list don’t recognize the value.

Reacting to events#

Get an email when a CRM rejects a contact#

add_action( 'wpsc_cloud_crm_sync_failed', function ( $slug, $error, $contact ) {
    wp_mail(
        get_option( 'admin_email' ),
        "WP Smart Consent: {$slug} rejected {$contact['email']}",
        $error->get_error_message()
    );
}, 10, 3 );

Fires for the 14 cloud CRMs. A failed CRM never interrupts the checkout or form.

Copy every opt-in to your own system#

add_action( 'wpsc_optin_trigger', function ( $optin, $order, $billing, $context ) {
    if ( ! $optin ) {
        return; // the visitor didn't tick the box
    }
    my_crm_push( $billing['email'], $billing['first_name'] ?? '', $context['source'] ?? '' );
}, 20, 4 );

Priority 20 runs after WP Smart Consent’s own destinations. For anything outside WordPress, a webhook usually needs no code at all.

Add a field to every webhook payload#

add_filter( 'wpsc_webhook_data_before_send', function ( $payload, $billing, $webhook ) {
    $payload['site_name'] = get_bloginfo( 'name' );
    return $payload;
}, 10, 3 );

The checkbox#

Allow another HTML tag in the label#

add_filter( 'wpsc_optin_label_allowed_html', function ( $allowed ) {
    $allowed['abbr'] = [ 'title' => true ];
    return $allowed;
} );

Add the filter before saving the label in General, or the tag is removed on save.

Show the opt-in label in your own template#

echo \WPSmartConsent\Helper\Utils::get_optin_label_html();

Translated (WPML or Polylang) and cleaned, ready to print. To build a full integration around it, see Build a Custom Integration.

Change the classic checkout row’s CSS classes#

add_filter( 'wpsc_field_class', function ( $classes ) {
    $classes[] = 'my-optin-row';
    return $classes;
} );

Use your theme’s colors for the checkbox#

New in 1.5.5. Filters change what’s used on the front end without saving it; to save the values into the settings instead, see Checkbox Color and Text Size.

Site setup#

Your site is behind Cloudflare or a load balancer#

Same as Geo rules → Behind a trusted proxy. Only use it when a proxy you control is really in front of the site; otherwise visitors could fake their IP address.

Keep the Audit Trail signing key out of the database#

Copy the line shown under Audit trail → How to use the audit trail → Signing key into wp-config.php:

Use the exact value shown. A different key makes existing signatures fail verification.

Turn on Brevo double opt-in#

Also switch on Double opt-in on the Brevo card’s Options tab.

Give a slow CRM more time#

Log diagnostics without WP_DEBUG#

Messages go to the PHP error log. Remove the snippet when you’re done.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only