/** * Create visitor class from visitor id * @param $visitor_id int unique visitor id * @since 3.8.14 */ function __construct($visitor_id) { $this->_cart = new wpsc_cart(); $visitor = _wpsc_get_visitor($visitor_id); if ($visitor == false) { $this->valid = false; return; } if ($visitor) { foreach ($visitor as $key => $value) { $property_name = '_' . $key; $this->{$property_name} = $value; } } $visitor_meta = wpsc_get_visitor_meta($visitor_id); if (!empty($visitor_meta)) { foreach ($visitor_meta as $meta_key => $meta_value) { if (($i = strpos($meta_key, 'cart.')) === false) { $property_name = '_' . $meta_key; $this->{$property_name} = $meta_value[0]; } else { $property_name = substr($meta_key, strlen('_wpsc_cart.')); $this->_cart->{$property_name} = $meta_value[0]; } } } $this->_cart = wpsc_get_visitor_cart($visitor_id); }
/** * Return an the customer cart * * @access public * @since 3.8.9 * @param mixed $id Customer ID. Default to the current user ID. * @return WP_Error|array Return an array of metadata if no error occurs, WP_Error * if otherwise. */ function wpsc_get_customer_cart($id = false) { global $wpsc_cart; if (!$id) { $id = wpsc_get_current_customer_id(); } // if we are using the current visitors cart then we have a global to use if ($id == wpsc_get_current_customer_id()) { if (empty($wpsc_cart)) { $wpsc_cart = wpsc_get_visitor_cart($id); } return $wpsc_cart; } else { return wpsc_get_visitor_cart($id); } }
/** * Deletes a WPEC visitor * * @since 3.8.14 * * @param int (optional) WPEC visitor id to update * @param $updates_array array of attributes to update * @return boolean true if successful */ function wpsc_delete_visitor($visitor_id) { if (!_wpsc_visitor_database_ready()) { return false; } if (empty($visitor_id) || $visitor_id == WPSC_BOT_VISITOR_ID) { return false; } // initialize row count changed $result = 0; $ok_to_delete_visitor = !(wpsc_visitor_has_purchases($visitor_id) && wpsc_visitor_post_count($visitor_id) && wpsc_visitor_comment_count($visitor_id)); if (!$ok_to_delete_visitor) { wpsc_visitor_remove_expiration($visitor_id); } else { global $wpdb; $ok_to_delete_visitor = apply_filters('wpsc_before_delete_visitor', $ok_to_delete_visitor, $visitor_id); // we explicitly empty the cart to allow WPEC hooks to run $cart = wpsc_get_visitor_cart($visitor_id); $cart->empty_cart(); // Delete all of the visitor meta $visitor_meta = wpsc_get_visitor_meta($visitor_id); foreach ($visitor_meta as $visitor_meta_key => $visitor_meta_value) { wpsc_delete_visitor_meta($visitor_id, $visitor_meta_key); } // Delete the visitor record $result = $wpdb->delete($wpdb->wpsc_visitors, array('id' => $visitor_id)); // if a WordPress user references the visitor being deleted we need to remove the reference $sql = 'SELECT user_id FROM ' . $wpdb->usermeta . ' WHERE meta_key = "_wpsc_visitor_id" AND meta_value = ' . $visitor_id; $user_ids = $wpdb->get_col($sql, 0); foreach ($user_ids as $user_id) { delete_user_meta($user_id, '_wpsc_visitor_id'); } do_action('wpsc_after_delete_visitor', $visitor_id); } // one row should be updated on success return $result === 1; }