Last active
April 5, 2021 22:00
-
-
Save scottbuscemi/a6ba1fbbcf9f07bb34f160fd7c9ab311 to your computer and use it in GitHub Desktop.
MailChimp for WooCommerce - Automatically uncheck the newsletter signup box for EU customers using Cloudflare geoip
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
jQuery(document).ready(function( $ ) { | |
if ($('body').hasClass("eu_customer")) { | |
$("#mailchimp_woocommerce_newsletter").prop('checked', false); | |
} | |
}); |
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
/** | |
* Body class for country on checkout page | |
* | |
*/ | |
add_filter( 'body_class','gsg_checkout_country_body_class' ); | |
function gsg_checkout_country_body_class( $classes ) { | |
if (is_page('checkout')) { | |
$eu_countries = array("BE", "BG", "CZ", "DK", "DE", "EE", "IE", "EL", "ES", "FR", "HR", "IT", "CY", "LV", "LT", "LU", "HU", "MT", "NL", "AT", "PL", "PT", "RO", "SI", "SK", "FI", "SE"); | |
$user_country = $_SERVER["HTTP_CF_IPCOUNTRY"]; | |
if (in_array($user_country, $eu_countries)) { | |
$classes[] = "eu_customer"; | |
} | |
} | |
return $classes; | |
} | |
function gsg_checkout_geo_script() { | |
if (is_page('checkout')) { | |
wp_enqueue_script( 'checkout-geo', plugin_dir_url( __FILE__ ) . 'js/checkout-geo.js', array ( 'jquery' ), 1.1); | |
} | |
} | |
add_action( 'wp_enqueue_scripts', 'gsg_checkout_geo_script' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment