recover-cart.php
2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
require_once($_SERVER["DOCUMENT_ROOT"].'/wp-blog-header.php');
require_once( plugin_dir_path( __FILE__ ) . '../vendor/active-campaign/ActiveCampaign.class.php' );
global $woocommerce;
$vars = get_object_vars($woocommerce->integrations);
$apiurl = $vars['integrations']['active-woo']->settings['api_url'];
$apikey = $vars['integrations']['active-woo']->settings['api_key'];
$ac = new ActiveCampaign($api_url, $api_key);
$default_tag = "AW_RC";
$acfname = $_POST['fname'];
$aclname = $_POST['lname'];
$acemail = $_POST['email'];
$actags = "";
$items = $woocommerce->cart->get_cart();
$actags .= $default_tag.",";
//var_dump($items);
foreach( $items as $item ) {
$product_variation_id = $item['variation_id'];
if ( $product_variation_id ) {
$variation = new WC_Product($item['variation_id']);
$skuvar = $variation->get_sku();
$product = new WC_Product($item['product_id']);
$sku = $product->get_sku();
} else {
$product = new WC_Product($item['product_id']);
$sku = $product->get_sku();
}
//now get the product's sku
if ( $skuvar ) {
$actags .= "AW_RC-".$sku.","."AW_RC-".$skuvar.",";
} else {
$actags .= "AW_RC-".$sku.",";
}
$terms = get_the_terms( $item['product_id'], 'product_cat' ); // now lets get the product categories and make those into tags
if ( !empty($terms) ) { //don't look for categories if there are none for this product
foreach ($terms as $term) {
$actags .= "AW_RC-".$term->name;
}
}
}//each items as item
$contact = array(
"email" => $acemail,
"first_name" => $acfname,
"last_name" => $aclname,
'tags' => $actags
);
$contact_sync = $ac->api("contact/sync", $contact);
echo "<p style='float:left; width: 40%;'><b>First Name: </b>".$acfname."</p>"."<p style='float:left; width: 40%;'><b>Last Name: </b>".$aclname."</p>".
"<p style='float:left; width: 100%;'><b>Email: </b>".$acemail."</p><p style='float:left; width: 100%;'><a href='/'>Edit</a></p>";
?>