WC_Shipping_Zone::add_location( string $code, string $type )
Add location (state or postcode) to a zone.
Description Description
Parameters Parameters
- $code
-
(Required) Location code.
- $type
-
(Required) state or postcode.
Source Source
File: includes/class-wc-shipping-zone.php
public function add_location( $code, $type ) {
if ( 0 !== $this->get_id() && $this->is_valid_location_type( $type ) ) {
if ( 'postcode' === $type ) {
$code = trim( strtoupper( str_replace( chr( 226 ) . chr( 128 ) . chr( 166 ), '...', $code ) ) ); // No normalization - postcodes are matched against both normal and formatted versions to support wildcards.
}
$location = array(
'code' => wc_clean( $code ),
'type' => wc_clean( $type ),
);
$zone_locations = $this->get_prop( 'zone_locations', 'edit' );
$zone_locations[] = (object) $location;
$this->set_prop( 'zone_locations', $zone_locations );
}
}