1. Home
  2. Docs
  3. ektagon WooCommerce to In...
  4. For Developers
  5. Filters and Actions

Filters and Actions

The plugin provides extensive hooks for customization:

Event Filters

// Modify event data before sending to Intercom
add_filter( 'ewi_event_data', function( $data, $user_id ) {
    $data['metadata']['custom_field'] = 'custom_value';
    return $data;
}, 10, 2 );

// Modify tag data
add_filter( 'ewi_tag_user_data', function( $data, $user_id ) {
    // Customize tag data
    return $data;
}, 10, 2 );

// Modify custom attributes
add_filter( 'ewi_custom_attribs_data', function( $data, $user_id ) {
    // Add or modify custom attributes
    return $data;
}, 10, 2 );

Metadata Filters

// Order completed metadata
add_filter( 'ewi_order_completed_meta', function( $metadata, $order ) {
    $metadata['payment_method'] = $order->get_payment_method();
    return $metadata;
}, 10, 2 );

// Product viewed metadata
add_filter( 'ewi_viewed_product_meta', function( $metadata, $product ) {
    $metadata['product_category'] = $product->get_category_ids();
    return $metadata;
}, 10, 2 );

Tag Filters

// Customize product tags
add_filter( 'ewi_product_tag', function( $tag, $tags_array, $product, $order ) {
    // Return custom tag name
    return 'Custom: ' . $tag;
}, 10, 4 );

// Customize category tags
add_filter( 'ewi_category_tag', function( $tag, $product, $user_id, $order_id ) {
    return strtoupper( $tag );
}, 10, 4 );

// Modify all tags before sending
add_filter( 'ewi_before_tagging_tags', function( $tags, $user_id, $order_id ) {
    // Add, remove, or modify tags
    return $tags;
}, 10, 3 );

// Modify Intercom widget settings for logged-in users
add_filter( 'ewi_footer_js_attribs', function( $init_array, $user_id ) {
    $init_array['custom_data'] = 'value';
    return $init_array;
}, 10, 2 );

// Modify settings for all visitors (including guests)
add_filter( 'ewi_footer_js_attribs_all_visitors', function( $init_array ) {
    $init_array['hide_default_launcher'] = true;
    return $init_array;
}, 10, 1 );

// Conditionally disable widget
add_filter( 'ewi_add_footer', function( $should_add, $current_user ) {
    // Return false to disable widget for specific users
    return $should_add;
}, 10, 2 );

Bulk Sync Filters

// Modify which user roles get synced
add_filter( 'ewi_bulk_sync_roles', function( $roles ) {
    $roles[] = 'subscriber';
    return $roles;
} );

// Customize bulk sync attributes
add_filter( 'ewi_bulk_sync_attribs', function( $attributes, $user_id ) {
    $attributes['lifetime_value'] = calculate_ltv( $user_id );
    return $attributes;
}, 10, 2 );

// Change bulk sync batch size
add_filter( 'ewi_bulk_sync_batch_size', function( $size ) {
    return 25; // Process 25 users at a time
} );

Subscription Filters

// Customize subscription event names
add_filter( 'ewi_subs_event_name', function( $event_title, $context ) {
    // $context values: 'payment_complete', 'payment_failed', 'status_active', etc.
    return $event_title;
}, 10, 2 );

// Modify subscription metadata
add_filter( 'ewi_subs_event_meta', function( $metadata, $subscription, $context ) {
    $metadata['billing_cycle'] = $subscription->get_billing_period();
    return $metadata;
}, 10, 3 );

// Customize subscriber tag name
add_filter( 'ewi_sub_tag_name', function( $tag ) {
    return 'Premium Subscriber';
} );

Action Hooks

// Before/after footer JS insertion
add_action( 'ewi_before_footer_js', function( $app_id, $init_array ) {
    // Run custom code before Intercom widget loads
}, 10, 2 );

add_action( 'ewi_after_footer_js', function( $app_id, $init_array ) {
    // Run custom code after Intercom widget loads
}, 10, 2 );