function test_has_region() { // UK $country = new WPSC_Country(self::COUNTRY_ID_WITHOUT_REGIONS); $has_region = $country->has_region(REGION_ID); $this->assertFalse($has_region); // Oregon is not in the UK $has_region = $country->has_region(-1); $this->assertFalse($has_region); // Non-existent region is not in the UK // USA $country = new WPSC_Country(self::COUNTRY_ID_WITH_REGIONS); $has_region = $country->has_region(REGION_ID); $this->assertTrue($has_region); // Oregon is in the USA $has_region = $country->has_region(self::REGION_NAME); $this->assertTrue($has_region); // Oregon is in the USA $has_region = $country->has_region(self::INVALID_REGION_NAME); $this->assertFalse($has_region); // Oregano is not $has_region = $country->has_region(-1); $this->assertFalse($has_region); // Imaginary state is not in the USA }
/** * 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'); } }