Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Created June 30, 2025 10:28
Show Gist options
  • Save xlplugins/e8394cfc099efaf7c9732cfa706dd119 to your computer and use it in GitHub Desktop.
Save xlplugins/e8394cfc099efaf7c9732cfa706dd119 to your computer and use it in GitHub Desktop.
Remove the frontend script a& metabox based on tracking settings
/**
* Conditionally removes the FunnelKit (WooFunnels) frontend tracking scripts.
*
* This function checks if the "Track UTMs" setting in FunnelKit's general settings
* is disabled. If it is, it removes the action responsible for enqueuing the
* e-commerce tracking scripts, preventing them from being loaded on the site's frontend.
*
* It hooks into 'wp_enqueue_scripts' with a very early priority (-1) to ensure
* it runs before the target action is executed.
*
* @since 1.0.0
*
* @see BWF_Ecomm_Tracking_Common::render()
* @see BWF_Admin_General_Settings::get_option()
*/
function fk_remove_tracking_scripts() {
// Find the WooFunnels global object and its tracking component.
if ( class_exists( 'BWF_Ecomm_Tracking_Common' ) && true !== wffn_string_to_bool( BWF_Admin_General_Settings::get_instance()->get_option( 'track_utms' ) ) ) {
remove_action( 'wp_enqueue_scripts', array( BWF_Ecomm_Tracking_Common::get_instance(), 'render' ), 1 );
}
}
add_action( 'wp_enqueue_scripts', 'fk_remove_tracking_scripts', -1 );
/**
* Conditionally removes the FunnelKit "Conversion Tracking" metabox.
*
* This function checks if the "Track UTMs" setting in FunnelKit's general settings
* is disabled. If it is, it removes the action responsible for adding the
* "Conversion Tracking" metabox to the WooCommerce order edit screen.
*
* This helps to declutter the admin interface when UTM tracking is not in use.
*
* @since 1.0.0
*
* @see BWF_Ecomm_Tracking_Common::add_single_order_meta_box()
* @see BWF_Admin_General_Settings::get_option()
*/
function fk_remove_conversion_tracking_metabox() {
// Find the WooFunnels global object and its tracking component.
if ( class_exists( 'BWF_Ecomm_Tracking_Common' ) && true !== wffn_string_to_bool( BWF_Admin_General_Settings::get_instance()->get_option( 'track_utms' ) ) ) {
remove_action( 'add_meta_boxes', array( BWF_Ecomm_Tracking_Common::get_instance(), 'add_single_order_meta_box' ), 50 );
}
}
add_action( 'init', 'fk_remove_conversion_tracking_metabox' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment