Skip to content

Commit

Permalink
feat: disable mailchimp-for-woocommerce plugin campaign tracking cook…
Browse files Browse the repository at this point in the history
…ie (#618)
  • Loading branch information
philipjohn authored Aug 16, 2022
1 parent 153e4a0 commit 99310cb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions includes/class-newspack.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ private function includes() {
include_once NEWSPACK_ABSPATH . 'includes/plugins/class-gravityforms.php';
include_once NEWSPACK_ABSPATH . 'includes/plugins/google-site-kit/class-googlesitekit.php';
include_once NEWSPACK_ABSPATH . 'includes/plugins/class-newspack-newsletters.php';
include_once NEWSPACK_ABSPATH . 'includes/plugins/class-mailchimp-for-woocommerce.php';

include_once NEWSPACK_ABSPATH . 'includes/class-patches.php';

Expand Down
39 changes: 39 additions & 0 deletions includes/plugins/class-mailchimp-for-woocommerce.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Mailchimp for WooCommerce integration class.
*
* @package Newspack
*/

namespace Newspack;

defined( 'ABSPATH' ) || exit;

/**
* Main class.
*/
class Mailchimp_For_WooCommerce {
/**
* Initialize hooks and filters.
*/
public static function init() {
// MC4WC fires it's hook at priority 10 so we need to move quicker.
add_action( 'init', [ __CLASS__, 'remove_campaign_tracking_cookie' ], 9 );
}

/**
* Disable the cookie added by the Mailchimp for WooCommerce (MC4WC) plugin when on
* a Newspack site because the cookie causes performance issues when logged out.
*/
public static function remove_campaign_tracking_cookie() {
// Don't do anything unless we know the MC4WC plugin is active.
if ( ! \class_exists( '\MailChimp_Service' ) ) {
return;
}

// Remove entirely the hook that sets the cookie.
$service = \MailChimp_Service::instance();
remove_action( 'init', [ $service, 'handleCampaignTracking' ] );
}
}
Mailchimp_For_WooCommerce::init();

0 comments on commit 99310cb

Please sign in to comment.