当他们使用 WooCommerce 进行购买时,如何将客户帐单信息添加到 MailChimp 组
Posted
技术标签:
【中文标题】当他们使用 WooCommerce 进行购买时,如何将客户帐单信息添加到 MailChimp 组【英文标题】:How do I add customer billing info to a MailChimp Group when they make a purchase using WooCommerce 【发布时间】:2013-01-10 12:19:52 【问题描述】:我想尽办法解决这个问题,但没有运气。我认为我缺少一些非常基本的东西,因为修复听起来很简单。
我正在尝试将客户帐单详细信息添加到 MailChimp 组。
适用于销售在线课程的网站。
我希望发生的是: 用户在现场进行购买,并根据他们的购买自动注册适当的 MailChimp 组(即用户购买每月视频课程,被添加到“每月视频课程”MailChimp 组。)
我已经编写了一些代码,但它不起作用(我收到“未定义变量”错误)。我不确定变量/语法是否正确。我绝不是码农。
有人可以帮助我吗?
这是我的代码(我把它放在functions.php中):
function pass_wp_to_mc()
require_once 'inc/MCAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey
require_once 'wp-content/plugins/woocommerce/classes/class-wc-checkout.php';
$api = new MCAPI($apikey);
// Grabs the WooCommerce Product IDs and associates them with the Mailchimp Group IDs - users are put into Groups based on product purchase.
if ($product_id == 42)
$mailchimpGroupingId = 1;
$mailchimpGroup = 'Monthly';
elseif ($product_id == 142)
$mailchimpGroupingId = 1;
$mailchimpGroup = 'Weekly';
else ($product_id == 144);
$mailchimpGroupingId = 1;
$mailchimpGroup = 'Audio';
$merge_vars = array(
'FNAME' => $billing_first_name,
'LNAME'=> $billing_last_name,
'EMAIL'=> $billing_email,
'GROUPINGS'=>array(
array('id'=>$mailchimpGroupingId, 'groups'=>$mailchimpGroup),
)
);
$listId = 33833; //List ID found inside MailChimp on the page for your List
$my_email = '$email';
$double_optin = false; // People are automatically added in to List
$update_existing = true; // Will update users if they are already on the list
$retval = $api->listSubscribe( $listId, $my_email, $merge_vars, $double_optin, $update_existing);
if ($api->errorCode)
echo "Unable to load listSubscribe()!\n";
echo "\tCode=".$api->errorCode."\n";
echo "\tMsg=".$api->errorMessage."\n";
else
echo "Subscribed - look for the confirmation email!\n";
我的问题是: 这段代码正确吗? 如果是这样,functions.php 是放置它的地方吗? 如果是这样,我如何“调用”它,我将把调用放在哪里 - WordPress 文件?电子商务?谢谢你.php?结帐.php?购物车.php?
非常感谢任何帮助 - 我已经尝试解决这个问题好几个星期了!
更新:我想通了!首先,代码不正确。这是有效的:
require_once dirname(__FILE__).'/inc/MCAPI.class.php';
require_once dirname(__FILE__).'/inc/config.inc.php';
add_action('woocommerce_checkout_order_processed', 'get_info');
function get_info($order_id)
global $woocommerce;
$order = new WC_Order( $order_id );
$firstname = $order->billing_first_name;
$lastname = $order->billing_last_name;
$email = $order->billing_email;
$product_id=unserialize($order->order_custom_fields["_order_items"][0]);
$product_id=$product_id[0]['id'];
global $apikey;
$api = new MCAPI($apikey);
if ($product_id == *GET THIS ID AT THE EDITING SCREEN OF YOUR PARTICULAR WOOCOMMERCE PRODUCT*)
$mailchimpGroup = '*ENTER THE NAME OF YOUR MAILCHIMP GROUP (NOT THE TITLE)*';
elseif ($product_id == *GET THIS ID AT THE EDITING SCREEN OF YOUR PARTICULAR WOOCOMMERCE PRODUCT*)
$mailchimpGroup = '*ENTER THE NAME OF YOUR MAILCHIMP GROUP (NOT THE TITLE)*';
else ($product_id == *GET THIS ID AT THE EDITING SCREEN OF YOUR PARTICULAR WOOCOMMERCE PRODUCT*);
$mailchimpGroup = '*ENTER THE *NAME* OF YOUR MAILCHIMP GROUP (NOT THE TITLE)*';
$merge_vars = array(
'FNAME' => $firstname,
'LNAME'=> $lastname,
//'EMAIL'=> $email,
'GROUPINGS'=>array(
array('name'=>'*ENTER THE TITLE OF YOUR MAICHIMP GROUP (NOT THE NAME)', 'groups'=>$mailchimpGroup),
)
);
$listId = 'YOUR LIST ID HERE'; //List ID found inside MailChimp on the page for your List
$my_email = $email;
$double_optin = false; // People are automatically added in to List
$update_existing = true; // Will update users if they are already on the list
$retval = $api->listSubscribe( $listId, $my_email, $merge_vars, $double_optin, $update_existing);
【问题讨论】:
非常感谢 Tom Roshko 帮助我调试! 请提交您的解决方案作为答案并将其标记为正确,这样该问题将被标记为已回答。谢谢 【参考方案1】:现在有一个插件 - 看看WooChimp - MailChimp WooCommerce Integration。这里有些人不太了解 PHP,所以我认为这可能会有所帮助。
完全披露:我是插件的作者。
【讨论】:
以上是关于当他们使用 WooCommerce 进行购买时,如何将客户帐单信息添加到 MailChimp 组的主要内容,如果未能解决你的问题,请参考以下文章
Woocommerce 订单状态挂起钩子不适用于 PayPal 交易
Woocommerce 客户在 Paypal 重定向之前退出
WooCommerce:通过 notify_URL 使用 PayPal