Created
August 3, 2026 12:00
-
-
Save xlplugins/317952152f493abda45772c4a8e6eac3 to your computer and use it in GitHub Desktop.
Custom FB Pixel & Token per checkout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Plugin Name: FunnelKit — Custom FB Pixel & Token per checkout / upsell | |
| * Description: Use a different Facebook pixel id + Conversions API access token on specific Aero checkout pages and specific upsell funnels. Every other page keeps the global pixel/token from settings. Add as many rows as needed. | |
| * Version: 1.1.0 | |
| */ | |
| defined( 'ABSPATH' ) || exit; | |
| /* ==== EDIT THESE ========================================================= | |
| * Add one row per checkout / upsell. Any id not listed keeps the global | |
| * pixel + token. 'pixel' / 'token' may be a single value or a comma list. | |
| * ======================================================================== */ | |
| // Aero checkout pages: checkout_page_id => pixel + token. | |
| function fk_custom_checkout_map() { | |
| return array( | |
| 19234 => array( 'pixel' => '111111111111111', 'token' => 'EAAxxxxxxxxxxxxxxxxx1' ), | |
| // 19235 => array( 'pixel' => '333333333333333', 'token' => 'EAAxxxxxxxxxxxxxxxxx3' ), | |
| ); | |
| } | |
| // Upsells: key by OFFER id (one specific offer) OR FUNNEL id (all offers in | |
| // that funnel). Offer id is checked first, then funnel id — list whichever | |
| // level you want to target. | |
| function fk_custom_upsell_map() { | |
| return array( | |
| 193424 => array( 'pixel' => '222222222222222', 'token' => 'EAAxxxxxxxxxxxxxxxxx2' ), | |
| // 193425 => array( 'pixel' => '444444444444444', 'token' => 'EAAxxxxxxxxxxxxxxxxx4' ), | |
| ); | |
| } | |
| /** | |
| * The pixel/token for the current upsell: match on offer id first, then funnel id. | |
| * | |
| * @param string $which 'pixel' or 'token'. | |
| * | |
| * @return string | |
| */ | |
| function fk_custom_upsell_value( $which ) { | |
| if ( ! function_exists( 'WFOCU_Core' ) || is_null( WFOCU_Core()->data ) ) { | |
| return ''; | |
| } | |
| $map = fk_custom_upsell_map(); | |
| $offer_id = absint( WFOCU_Core()->data->get_current_offer() ); | |
| $funnel_id = absint( WFOCU_Core()->data->get_funnel_id() ); | |
| $v = fk_custom_lookup( $map, $offer_id, $which ); | |
| if ( '' === $v ) { | |
| $v = fk_custom_lookup( $map, $funnel_id, $which ); | |
| } | |
| return $v; | |
| } | |
| /* ======================================================================== */ | |
| /** | |
| * Return the mapped value for an id, or '' when the id isn't in the map. | |
| * | |
| * @param array $map Config map. | |
| * @param int $id Checkout / funnel id. | |
| * @param string $which 'pixel' or 'token'. | |
| * | |
| * @return string | |
| */ | |
| function fk_custom_lookup( $map, $id, $which ) { | |
| return ( isset( $map[ $id ][ $which ] ) && '' !== $map[ $id ][ $which ] ) ? $map[ $id ][ $which ] : ''; | |
| } | |
| // --- Aero checkout page events, per checkout id --- | |
| add_filter( 'wfacp_fb_pixel_ids', function ( $pixel ) { | |
| $id = class_exists( 'WFACP_Common' ) ? absint( WFACP_Common::get_id() ) : 0; | |
| $v = fk_custom_lookup( fk_custom_checkout_map(), $id, 'pixel' ); | |
| return '' !== $v ? $v : $pixel; | |
| }, 99 ); | |
| add_filter( 'wfacp_conversion_api_access_token', function ( $token ) { | |
| $id = class_exists( 'WFACP_Common' ) ? absint( WFACP_Common::get_id() ) : 0; | |
| $v = fk_custom_lookup( fk_custom_checkout_map(), $id, 'token' ); | |
| return '' !== $v ? $v : $token; | |
| }, 99 ); | |
| // --- Upsell events, per offer id (then funnel id) --- | |
| add_filter( 'wfocu_fb_pixel_ids', function ( $pixel ) { | |
| $v = fk_custom_upsell_value( 'pixel' ); | |
| return '' !== $v ? $v : $pixel; | |
| }, 99 ); | |
| add_filter( 'wfocu_tracking_conversion_api_access_token', function ( $token ) { | |
| $v = fk_custom_upsell_value( 'token' ); | |
| return '' !== $v ? $v : $token; | |
| }, 99 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment