/** * Delete customer meta. * * Implement your own system by hooking into 'wpsc_delete_customer_meta'. * * @access public * @since 3.8.9 * @param string $key Meta key * @param string|int $id Customer ID. Optional. Defaults to current customer. * @return boolean|WP_Error True if successful. False if not successful. WP_Error * if there are any errors. */ function wpsc_delete_customer_meta($key, $id = false) { if (!$id) { $id = wpsc_get_current_customer_id(); } $result = apply_filters('wpsc_delete_customer_meta', null, $key, $id); if ($result) { return $result; } return wpsc_delete_visitor_meta($id, $key); }
/** * Update any values dependant on billing country * * @since 3.8.14 * * @access private * @param mixed $meta_value Optional. Metadata value. * @param string $meta_key Metadata name. * @param int $visitor_id visitor ID * @return none */ function _wpsc_updated_visitor_meta_billingcountry($meta_value, $meta_key, $visitor_id) { $old_billing_state = wpsc_get_visitor_meta($visitor_id, 'billingstate', true); $old_billing_region = wpsc_get_visitor_meta($visitor_id, 'billingregion', true); if (!empty($meta_value)) { // check the current state and region values, if either isn't valid for the new country delete them $wpsc_country = new WPSC_Country($meta_value); if (!empty($old_billing_state) && $wpsc_country->has_regions() && !$wpsc_country->has_region($old_billing_state)) { wpsc_delete_visitor_meta($visitor_id, 'billingstate'); } if (!empty($old_billing_region) && $wpsc_country->has_regions() && !$wpsc_country->has_region($old_billing_region)) { wpsc_delete_visitor_meta($visitor_id, 'billingregion'); } } else { wpsc_delete_visitor_meta($visitor_id, 'billingstate'); wpsc_delete_visitor_meta($visitor_id, 'billingregion'); } }
/** * Get a deprecated customer meta value that mirrors what was once "checkout_details". * * @since 3.8.14 * @param string|int $id Customer ID. Optional. Defaults to current customer * @return array checkout details array */ function _wpsc_update_deprecated_visitor_meta_checkout_details($meta_data_in_old_format, $key = 'checkout_details', $id = null) { global $wpdb; if (!$id) { $id = wpsc_get_current_customer_id(); } $form_sql = 'SELECT * FROM `' . WPSC_TABLE_CHECKOUT_FORMS . '` WHERE `active` = "1" ORDER BY `checkout_set`, `checkout_order`;'; $form_data = $wpdb->get_results($form_sql, ARRAY_A); foreach ($form_data as $index => $form_field) { if (isset($meta_data_in_old_format[$form_field['id']])) { $meta_key = $form_field['unique_name']; $meta_value = $meta_data_in_old_format[$form_field['id']]; switch ($form_field['type']) { case 'delivery_country': if (is_array($meta_value) && count($meta_value) == 2) { wpsc_update_visitor_meta($id, 'shippingcountry', $meta_value[0]); wpsc_update_visitor_meta($id, 'shippingregion', $meta_value[1]); } else { if (is_array($meta_value)) { $meta_value = $meta_value[0]; } wpsc_update_visitor_meta($id, 'shippingcountry', $meta_value); wpsc_update_visitor_meta($id, 'shippingregion', ''); } break; case 'country': if (is_array($meta_value) && count($meta_value) == 2) { wpsc_update_visitor_meta($id, 'billingcountry', $meta_value[0]); wpsc_update_visitor_meta($id, 'billingregion', $meta_value[1]); } else { if (is_array($meta_value)) { $meta_value = $meta_value[0]; } wpsc_update_visitor_meta($id, 'billingcountry', $meta_value); wpsc_update_visitor_meta($id, 'billingregion', ''); } break; default: wpsc_update_visitor_meta($id, $meta_key, $meta_value); break; } } } $deprecated_meta_value = wpsc_get_visitor_meta($id, $key, true); if (!empty($deprecated_meta_value)) { wpsc_delete_visitor_meta($id, $key); } return $meta_data_in_old_format; }
function _wpsc_visitor_location_clear_tracked_changes($visitor_id = false) { if (!$visitor_id) { $visitor_id = wpsc_get_current_customer_id(); } wpsc_delete_visitor_meta($visitor_id, 'location_attributes_changed'); return true; }
/** * Delete visitor attribute * @param $attribute attribute name * @return this * @since 3.8.14 */ function delete($attribute) { $property_name = '_' . $attribute; if (isset($this->{$property_name})) { unset($a->{$property_name}); } wpsc_delete_visitor_meta($this->_id, $attribute); return $this; }