Applying and Removing Tags with JavaScript

Applying and Removing Tags with JavaScript

#Overview
WP Fusion has a basic JavaScript API that lets you apply and remove tags from the current logged in user.
The AJAX methods are apply_tags and remove_tags, and they accept a comma-separated list of tags.
Note, to make use of the wpf_ajax.ajaxurl variable, Link Click Tracking should be turned on in the WP Fusion settings, on the Advanced tab. You can also use your own ajaxurl variable.
#Examples
#Apply tags with JavaScript
var data = {
'action' : 'apply_tags',
'tags' : 'Tag One, Tag Two'
};

$.post(wpf_ajax.ajaxurl, data);

#Remove tags with JavaScript
var data = {
'action' : 'remove_tags',
'tags' : 'Tag One, Tag Two'
};

$.post(wpf_ajax.ajaxurl, data);

#Additional examples
Also see this tutorial by WPAutomationLab on using WP Fusion』s JavaScript API with Google Tag Manager.

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

Additional Code Examples

Additional Code Examples

#Overview
We have a growing library of code examples for WP Fusion over at GitHub. Some examples:
#Access Control
#Add the current user』s tags as classes to the HTML body element:

#Delete a user in WordPress when a specific tag is applied:

#Bypass WP Fusion』s content restriction on RSS feed content:

#Unlock any locked content when visited from a Facebook link:

#Bypass WP Fusion』s content protection when someone accesses your site from a specific IP address:

#Syncing Data
#Sets users imported by webhook to have usernames generated from their first and last names, instead of email address:

#Extends the HTTP timeout to 60 seconds:

#Custom Objects
#Change CRM object type to Leads for Salesforce:

#Create / update a custom object in Zoho or Salesforce when a post is updated:

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

wpf_woocommerce_payment_complete

wpf_woocommerce_payment_complete

#Overview
This action is triggered whenever WP Fusion has completed processing a WooCommerce order
#Parameters

$order_id: (int) The order ID
$contact_id: (string) The contact ID that was created or updated at checkout

#Examples
#Send a custom field to your CRM
The example below will update a custom field in the CRM (with key order_total) with the order total after an order has been placed.
function my_woo_payment_complete( $order_id, $contact_id ) {

$order = wc_get_order( $order_id );

$update_data = array( 'order_total' => $order->get_total() );

wp_fusion()->crm->update_contact( $contact_id, $update_data, false );

}

add_action( 'wpf_woocommerce_payment_complete', 'my_woo_payment_complete', 10, 2 );

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

wpf_user_updated

wpf_user_updated

#Overview
This action is triggered whenever updated meta data is loaded from a CRM contact record for a user.
#Parameters

$user_id: The user ID
$user_meta: An array of meta fields loaded from the CRM

#Examples
#Update a user』s role based on the value of a custom field
function my_set_custom_role( $user_id, $user_meta ) {

if ( 'Active' == $user_meta['custom_field_key'] ) {

$user = new WP_User( $user_id );
$user->set_role( 'active-role' );

}

}

add_action( 'wpf_user_updated', 'my_set_custom_role', 10, 2 );

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

wpf_user_imported

wpf_user_imported

#Overview
This action is triggered whenever a new user is imported from your CRM (usually via a webhook), and after the user account has been created.
#Parameters

$user_id: The user ID of the newly created user
$user_meta: The meta data imported with the new user

#Examples
#Send a welcome email
The example below will send a welcome email to the new user containing their generated password.
function my_import_notification( $user_id, $user_meta ) {

$to = $user_meta['user_email'];
$subject = 'Welcome to ' . get_bloginfo();
$message = "You have a new user account on " . get_bloginfo() . ":nn";
$message .= "Username: " . $user_meta['user_email'] . "n";
$message .= "Password: " . $user_meta['user_pass'] . "n";

wp_mail( $to, $subject, $message );

}

add_action( 'wpf_user_imported', 'my_import_notification', 10, 2 );
#Apply a tag
The example below will apply a tag with ID 123 to any new user after they』ve been successfully imported.
function my_import_tag( $user_id, $user_meta ) {

wp_fusion()->user->apply_tags( array( '123' ), $user_id );

}

add_action( 'wpf_user_imported', 'my_import_tag', 10, 2 );

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

wpf_tags_modified

wpf_tags_modified

#Overview
This action is triggered whenever a user』s tags are modified.
#Parameters

$user_id: The user ID
$user_tags: An array of tags currently applied to the user

#See also

wpf_tags_applied: Triggered whenever tags are added to a user
wpf_tags_removed: Triggered whenever tags are removed from a user

#Examples
#Remove a tag when another tag is applied
WP Fusion includes a lot of interfaces for applying tags, but because removing tags is less common most of our integrations don』t include options for removing tags.
This example removes the tag Pending Signup when the tag Profile Complete is applied.
function remove_pending_signup_tag( $user_id, $tags_applied ) {

$tag_to_check = wpf_get_tag_id( 'Profile Complete' );
$tag_to_remove = wpf_get_tag_id( 'Pending Signup' );

if ( in_array( $tag_to_check, $tags_applied ) ) {
wp_fusion()->user->remove_tags( array( $tag_to_remove ), $user_id );
}

}

add_action( 'wpf_tags_applied', 'remove_pending_signup_tag', 10, 2 );

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

wpf_pushed_user_meta

wpf_pushed_user_meta

#Overview
This action is triggered whenever WP Fusion has synced metadata to the CRM for a user.
#Parameters

$user_id: The user ID
$contact_id: The ID of the contact that was updated in the CRM
$user_meta: The metadata that was synced to the CRM

#Examples
#Generic example
function generic_function( $user_id, $contact_id, $user_meta ) {

if ( 'Active' == $user_meta['custom_field_key'] ) {
// Do something here.
}
}

add_action( 'wpf_pushed_user_meta', 'generic_function', 10, 3 );

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

wpf_forms_post_submission

wpf_forms_post_submission

#Overview
This action is run when WP Fusion has finished processing a form entry from one of our supported form plugins.
It can be used to perform additional actions with the contact ID that was created in your CRM, for example triggering an event, or updating a note/opportunity.
To use the code examples below, add them to your active theme』s functions.php file.
#Parameters

$update_data (array): This is an array of data that was synced to the CRM
$user_id (int): The user who submitted the form, 0 if a guest
$contact_id (string): The ID of the contact record created / updated by the form submission
$form_id (int): The ID of the submitted form

#Examples
#Redirect an Elementor forms submission to an auto-login URL on another site
This example runs when an Elementor form is submitted and overrides the form』s redirect to https://siteb.com/?cid=Xwhere X is the ID of the contact record that was just created or updated by WP Fusion.
This redirect will then start an auto-login session for that contact on https://siteb.com
function wpf_custom_redirect( $update_data, $user_id, $contact_id, $form_id ) {

if ( wp_doing_ajax() ) {

$redirect_url = 'https://siteb.com';
$query_args = array( 'cid' => $contact_id );

wp_send_json_success( [
'message' => 'Success!',
'data' => array( 'redirect_url' => add_query_arg( $query_args, $redirect_url ) ),
] );
}

}

add_action( 'wpf_forms_post_submission', 'wpf_custom_redirect', 10, 4 );

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

wp_fusion_init

wp_fusion_init

#Overview
This action is triggered after WP Fusion has loaded (specifically on the init hook at priority 0).
It can be used to initialize any functionality that depends on WP Fusion.
Note: This action will not fire if WP Fusion is not connected to a CRM.
#Examples
#Register an additional order status for sync
This example registers a custom WooCommerce order status tbh-unpaid for sync with your CRM.
function wpf_add_custom_order_status() {

add_action( 'woocommerce_order_status_tbh-unpaid', array( wp_fusion()->integrations->woocommerce, 'process_order' ) );

}

add_action( 'wp_fusion_init', 'wpf_add_custom_order_status' );

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

Ontraport Abandoned Cart Tracking

Ontraport Abandoned Cart Tracking

There are a lot of strategies for tracking and following up on abandoned carts. This guide will provide an overview of how to set up a basic abandoned cart tracking workflow for Ontraport.
abandoned-cart-config
First, go to the Addons tab under the WP Fusion settings and select a tag to be used for abandoned cart tracking. You use an existing tag, or type a new one into the box. WP Fusion will automatically apply this tag to the user when checkout is begun, and the tag will be removed if checkout is completed successfully.
Next, log into your Ontraport account, select Campaigns from the Contacts dropdown, and create a new Campaign. The campaign should be triggered when the 「Abandoned Cart」 tag is added.

Add a timer (one hour is usually a good amount), and after the timer create a condition like in the picture below.

Anything under the 「Yes」 part of the condition will be run if the contact has begun checkout but hasn』t completed it within the specified time. From here you can add the contact to a list, send an email, and/or create an internal task for further followup. See the image below for an overview of the entire campaign.

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No