SureCart: Assign a FluentCRM Tag

Tech Articles | May 25, 2025 | Automation, Blog, Coding, FluentCRM, SureCart, Wordpress

In the last of this particular series, I now build on understanding what a price ID is and how checkout confirmation works in Surecart, and now we do something with that data.

In our case, we are going to assign a FluentCRM tag to our incoming orders, depending on the Price ID, which will depend on the tags we assign.

So, the first thing we need to understand is adding tags programmatically with FluentCRM. This is actually really easy. The documentation for this is available here and is pretty clear.

It’s clear from the documentation that there is some Laravel going on here https://laravel.com/docs/eloquent#retrieving-or-creating-models, so I decided to use firstOrNew

We then know we want to get a block together that does something like the below;

$subscriber = \FluentCrm\App\Models\Subscriber::firstOrNew( [ 'email' => $email ] );
$subscriber->save();
$subscriber->attachTags( $Variable );
PHP

First, FluentCRM can already do this using automation if you have the pro version, and SurelyWPs Toolbox can also do its own types of automation, but this is for users who don’t want to buy those tools and maybe only want to do it for one or two tags.

Let’s build it

Now we have the FluentCRM built, we just need to begin pulling it together:

  1. Grab Our Checkout item
  2. Map our Price IDS
  3. Check Price IDs and Assign tags if they match
  4. Add tags to ethe mail if matches happen.

With all that in mind, we end up with something very similar to the below;

<?php
add_action( 'surecart/checkout_confirmed', 'sc_log_checkout_and_apply_tags', 10, 1 );

function sc_log_checkout_and_apply_tags( $checkout_payload ) {
    // 1) Log the full payload
    if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
        error_log( 'SureCart Checkout Payload: ' . print_r( $checkout_payload, true ) );
    }

    // 2) Map price IDs to FluentCRM tags
    $price_to_tags = [
        '5fd6a72e-83de-48dd-95ef-f704124d2b74' => [ 'event-tickets'],
        'bef0c3ac-a144-4299-9817-9e88153ed88f' => [ 'another-event', 'vip' ],
        // etc...
    ];

    // 3) Collect matching tags
    $tags_to_apply = [];
    if ( ! empty( $checkout_payload->purchases->data ) && is_array( $checkout_payload->purchases->data ) ) {
        foreach ( $checkout_payload->purchases->data as $purchase ) {
            if ( ! empty( $purchase->price ) && isset( $price_to_tags[ $purchase->price ] ) ) {
                $tags_to_apply = array_unique( array_merge( $tags_to_apply, $price_to_tags[ $purchase->price ] ) );
            }
        }
    }

    // 4) Apply tags if any
    if ( ! empty( $tags_to_apply ) ) {
        // grab the purchaser email
        $email = $checkout_payload->billing->email
               ?? $checkout_payload->customer->email
               ?? '';

        if ( $email ) {
            // NOTE: fully‐qualified class name here
            $subscriber = \FluentCrm\App\Models\Subscriber::firstOrNew( [ 'email' => $email ] );
            $subscriber->save();
            $subscriber->attachTags( $tags_to_apply );

            error_log( sprintf(
                'Applied tags (%s) to %s',
                implode( ',', $tags_to_apply ),
                $email
            ) );
        } else {
            error_log( 'Could not find purchaser email; tags not applied.' );
        }
    } else {
        error_log( 'No matching price IDs; nothing to do.' );
    }
}
PHP

You can view the video for this tutorial here:

Taking this a step further

If you don’t want to build this, I use a tool I built called Tag Manager for SureCart that does just this, it’s not currently available as a purchasable item, but I am prepared to release it as a code base plugin in much the same way as I did Commerce Bridge for Hoster this will likely be £20-75 as the name your price amount

Crm tag manager admin screen

It autopulls in your available tags from FluentCRM for quick deployment of your tags.

Support the Author

buy me a coffee
Really Useful Plugin Logo
Wpvideobank temp
Appoligies for any spelling and grammer issue. As a dyslexic i need to rely on tools for this they like me are not perfect but I do try my best