Changing the list based on custom logic
By default the plugin subscribes the user to the Mailchimp list you select on the settings screen.
However, if you have custom logic based on the user address, language, etc. that needs to change which list the customer is subscribed to you can use the ss_wc_mailchimp_subscribe_options hook to modify the Mailchimp subscribe options:
/************ MAILCHIMP INTEGRATION HOOKS *********/
add_filter( 'ss_wc_mailchimp_subscribe_options', 'woocommerce_mailchimp_change_list', 10, 2 );
function woocommerce_mailchimp_change_list( $subscribe_options, $order_id ) {
/*
$subscribe_options will look like this:
$subscribe_options = array(
'list_id' => '12345',
'email' => 'user@example.com',
'merge_tags' => array('FNAME' => 'Joe', 'LNAME' => 'Smith'),
'interest_groups' => array( 'abcdefg', 'hijklmn' ), // MailChimp interest group IDs
'email_type' => 'html',
'double_opt_in' => false
);
*/
// Change the listid (You'll need to lookup the list ID in MailChimp or by
// inspecting element on the plugin settings page and making a note of
// the values in the drop-down
$subscribe_options['list_id'] = '12345';
// You can even change the list based on the product(s) purchased
// by using the passed $order_id
// Lets grab the order
$order = new WC_Order( $order_id );
$order_item = $order->get_items();
foreach( $order_item as $product ) {
$sku = $product->get_sku();
// here you could change the list based on a sku
if ( $sku = 'abcde' ) {
$subscribe_options['list_id'] = '6789';
break;
}
}
// Optionally, change other subscribe options
$subscribe_options['double_opt_in'] = true;
return $subscribe_options;
}
The pro version includes an easy way to setup product-specific lists, interest groups and tags.