Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Last active February 27, 2024 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimcoleman/e44166a059dcb0b132587aa5d998ae1b to your computer and use it in GitHub Desktop.
Save kimcoleman/e44166a059dcb0b132587aa5d998ae1b to your computer and use it in GitHub Desktop.
Add tags to contacts in FluentCRM when viewing a post in a specific category.
<?php
// Add tags to contacts when viewing a post in a specific category.
function update_contact_tags_on_post_view() {
// Return if they aren't logged in.
if ( ! is_user_logged_in() ) {
return;
}
// Return if the FluentCrmApi is not available.
if ( ! function_exists( 'FluentCrmApi' ) ) {
return;
}
// Check if we are viewing a single post and if the post is in the 'recipes' category.
if ( is_single() && has_category('recipes') ) {
// Get the current contact.
$contact = FluentCrmApi('contacts')->getCurrentContact();
if ( $contact ) {
$tagsToAdd = [4]; // Specify the tag IDs you want to add.
// Attach the tags to the contact.
$contact->attachTags($tagsToAdd);
}
}
}
add_action( 'memberlite_after_content_single', 'update_contact_tags_on_post_view' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment