将客户和订单详细信息发送给Mailchimp

时间:2018-06-01 10:28:10

标签: php woocommerce mailchimp mailchimp-api-v3.0

我成功订阅了用户并将数据发送到Mailchimp,以便在woocommerce checkout使用此代码填充列表:

<?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' ] );
    }

当用户在我的网站上下订单时,此代码会成功发送用户详细信息(姓名,地址,城市等),但我也需要发送订单详细信息(产品名称,价格等)。 Mailchimp API guide is really basic and difficult to understand for me. 我疯了谷歌搜索一些没有运气的帮助。

0 个答案:

没有答案