/
wooCommerceMailChimp.php
45 lines (35 loc) · 1.39 KB
/
wooCommerceMailChimp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/*
* Add checkbox at checkout page which is checked by default
* When user checkouts he automatically get subscribe to mail chimp
*/
/*
* Add the follwing code to payment page tempalate of woocommerce
*
*/
do_action( 'woocommerce_review_order_before_submit' ); // add after this line ?>
<label style="display: inline-block;float: left">
<input type="checkbox" name="newsletter_signup" value="1" checked>
Yes, I'd like to receive email updates!
</label>
<?php
// Add follwing code to function.php
/**
* check if email is already singup else subscribe mail with mailchimp
*/
add_action( 'woocommerce_checkout_update_order_meta', 'add_user_to_mailchimp' );
function add_user_to_mailchimp( $order_id ) {
/*
* signup user for mailchimp newsletter
*/
if (isset($_POST['newsletter_signup'])) {
if(class_exists('GF_MailChimp_Bootstrap')){
require_once ABSPATH . '/wp-content/plugins/gravityformsmailchimp/api/Mailchimp.php';
$api_key = "ed4ac31debf0bed4a0d710639aa1d3a3-us3";
$list_id = "d41e211c8f";
$Mailchimp = new Mailchimp( $api_key );
$Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );
$subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => htmlentities($_POST['billing_email']) ),array(),'html',true,true,true,false );
}
}
}