Skip to content

Instantly share code, notes, and snippets.

@allendav
Created May 31, 2018 23:43
Show Gist options
  • Save allendav/3cd1bb56bd0646840013d58e68c23ac9 to your computer and use it in GitHub Desktop.
Save allendav/3cd1bb56bd0646840013d58e68c23ac9 to your computer and use it in GitHub Desktop.
/**
* @param $email_address
* @param int $page
* @return array
*/
public function export($email_address, $page = 1)
{
global $wpdb;
$uid = mailchimp_hash_trim_lower($email_address);
$data = array();
if (get_site_option('mailchimp_woocommerce_db_mailchimp_carts', false)) {
$table = "{$wpdb->prefix}mailchimp_carts";
$statement = "SELECT * FROM $table WHERE id = %s";
$sql = $wpdb->prepare($statement, $uid);
if (($saved_cart = $wpdb->get_row($sql)) && !empty($saved_cart)) {
$data = array('name' => __('Email Address'), 'value' => $email_address);
}
}
// If nothing found, return nothing
if ( is_array( $data ) && ( count( $data ) < 1 ) ) {
return ( array( 'data' => array(), 'done' => true ) );
}
return array(
'data' => array(
array(
'group_id' => 'mailchimp_cart',
'group_label' => __( 'MailChimp Shopping Cart Data', 'mailchimp-woocommerce' ),
'item_id' => 'mailing-shopping-cart-1',
'data' => array(
array(
'name' => __( 'User ID', 'mailchimp-woocommerce' ),
'value' => $uid,
),
$data, // this is already an associative array with name and value keys
)
)
),
'done' => true,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment