将客户和订单详细信息发送到mailchimp [英] Send customer and order details to mailchimp

查看:77
本文介绍了将客户和订单详细信息发送到mailchimp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



当用户在我的网站上下订单时此代码发送成功的用户详细信息(名称,地址,城市等),但我也需要发送订单详细信息(产品名称,价格等)。 Mailchimp API指南对我来说非常基本且难以理解。我疯了谷歌搜索一些没有运气的帮助。提前致谢!



我尝试过:



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

推荐答案

api_key ='xxxx';
api_key = 'xxxx';


list_id ='xxxx ';
list_id = 'xxxx';


billing_email = htmlentities(
billing_email = htmlentities(


这篇关于将客户和订单详细信息发送到mailchimp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆