Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I successfully subscribe user and send data to Mailchimp to populate a list using this code at woocommerce checkout.

When a user place an order on my website this code send successfully user details (name, address, city etc) but I need to send the order details too (product name, price etc). Mailchimp API guide is really basic and difficult to understand for me. I went crazy googling for some help with no luck. Thanks in advance!

What I have tried:

<?php    
add_action( 'woocommerce_checkout_update_order_meta', 'mailchimp_checkout_update', 1, 2 );

    function mailchimp_checkout_update() {
        $api_key = 'xxxx';
        $list_id = 'xxxx';

        $billing_email = htmlentities( $_POST[ billing_email ] );
        $fname = htmlentities( $_POST[ billing_first_name ] );
        $lname = htmlentities( $_POST[ billing_last_name ] );
        $address = htmlentities( $_POST[ billing_address_1 ] );
        $phone = htmlentities( $_POST[ billing_phone ] );
        $city = htmlentities( $_POST[ billing_city ] );

        $args = array(
            'method' => 'PUT',
            'headers' => array(
                'Authorization' => 'Basic ' . base64_encode( 'user:' . $api_key )
            ),
            'body' => json_encode( array(
                'email_address' => $billing_email,
                'status' => 'subscribed',
                'merge_fields' => array(
                    'FNAME' => $fname,
                    'LNAME' => $lname,
                    'ADDRESS' => $address,
                    'PHONE' => $phone,
                    'CITY' => $city,

                ),

            ) )
        );

        $response = wp_remote_post( 'https://' . substr( $api_key, strpos( $api_key, '-' ) + 1 ) . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/' . md5( strtolower( $billing_email ) ), $args );
        $body = json_decode( $response[ 'body' ] );
    }
Posted
Comments
Richard Deeming 4-Jun-18 11:20am    
MailChimp stores the details of people who have subscribed to your mailing list. Whilst you can store additional information in the "merge fields", it is not a general data store; you can't store multiple rows of data against a single subscriber.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900