recover-cart.php 2.08 KB
<?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>";

?>