gpt4 book ai didi

php - 当客户使用 WooCommerce 进行购买时,如何将他们的账单信息添加到 MailChimp 组

转载 作者:可可西里 更新时间:2023-11-01 13:00:15 26 4
gpt4 key购买 nike

为了解决这个问题,我四处寻找,但没有运气。我想我遗漏了一些非常基本的东西,因为修复听起来很简单。

我正在尝试将客户账单详细信息添加到 MailChimp 组。

它适用于销售在线类(class)的网站。

我希望发生的是:用户在现场购买并根据他们的购买自动注册合适的 MailChimp 组(即用户购买每月视频类(class),被添加到“每月视频类(class)”MailChimp 组。)

我已经编写了一些代码,但它不起作用(我收到“ undefined variable ”错误)。我不确定变量/语法是否正确。我绝不是编码员。

有人可以帮助我吗?

这是我的代码(我放在 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? cart.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);

最佳答案

现在有一个插件 - 看看 WooChimp - MailChimp WooCommerce Integration .这里有些人不太了解 PHP,所以我认为这可能会有所帮助。

完全披露:我是插件的作者。

关于php - 当客户使用 WooCommerce 进行购买时,如何将他们的账单信息添加到 MailChimp 组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14540389/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com