Skip to content

Instantly share code, notes, and snippets.

@danielcharrua
Last active April 6, 2023 12:35
Show Gist options
  • Save danielcharrua/487dda60c373a40a7cbc8f412885b91b to your computer and use it in GitHub Desktop.
Save danielcharrua/487dda60c373a40a7cbc8f412885b91b to your computer and use it in GitHub Desktop.
Block third party cookies with GDPR Cookie Compliance WordPress plugin
<?php
/* Force page reload on gpdr_cookie accept */
add_action('gdpr_force_reload', '__return_true');
/*
* Disable cookie for Omnisend for Woocommerce
* Here we are disabling a plugin option, the filter does not exists inside the plugin
* We are directly changing an option value using https://developer.wordpress.org/reference/hooks/option_option/
* https://wordpress.org/plugins/omnisend-connect/
*/
add_filter( 'option_omnisend_account_id', 'load_omnisend_with_consent', 10, 2 );
function load_omnisend_with_consent( $value, $option ) {
if (function_exists('gdpr_cookie_is_accepted')) :
if (gdpr_cookie_is_accepted('thirdparty')) :
return $value;
endif;
endif;
return null;
}
/*
* Disable cookie for Facebook for WooCommerce
* https://wordpress.org/plugins/facebook-for-woocommerce/
*/
add_filter('facebook_for_woocommerce_integration_pixel_enabled', 'gdpr_cookie_facebook_wc', 20);
function gdpr_cookie_facebook_wc()
{
$enable_fb_wc = true;
if (function_exists('gdpr_cookie_is_accepted')) :
$enable_fb_wc = gdpr_cookie_is_accepted('thirdparty');
endif;
return $enable_fb_wc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment