Hi there! Want
to see some
related articles?

Sending WooCommerce order information to MailChimp

By default the plugin only sends the MailChimp default fields of EMAIL, FNAME and LNAME. However, with a little bit of code dropped into your functions.php file you can send additional information to MailChimp.

Below is some sample code on how to use the `ss_wc_mailchimp_subscribe_merge_tags` hook to modify the MailChimp merge tags to include WooCommerce order information:


/************ MAILCHIMP INTEGRATION HOOKS *********/
add_filter( 'ss_wc_mailchimp_subscribe_merge_tags', 'woocommerce_mailchimp_extra_data', 10, 3 );

function woocommerce_mailchimp_extra_data( $merge_tags, $order_id, $email ) {

    // Lets grab the order
    $order = new WC_Order( $order_id );
    $billing_date = $order->billing_date;
    $billing_total = $order->get_total();
    $order_number= $order->get_order_number();
    $product_list = '';

    $order_item = $order->get_items();

    foreach( $order_item as $product ) {
        $sku = $product->get_sku();
    }

    $product_list = implode( ',\n', $sku);

    $new_merge_tags = array(
        'BUYDATE' => $order->order_date,
        'AMOUNT' => $billing_total,
        'PRODUCTS' => $product_list,
        'SOURCE' => $order_number
    );

    // combine the two arrays
    $merge_tags = array_merge( $merge_tags, $new_merge_tags );

    return $merge_tags;
}