WC_Shipping_Zone::add_location
Add location (state or postcode) to a zone.
Method of the class: WC_Shipping_Zone{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WC_Shipping_Zone = new WC_Shipping_Zone(); $WC_Shipping_Zone->add_location( $code, $type );
- $code(string) (required)
- Location code.
- $type(string) (required)
- state or postcode.
WC_Shipping_Zone::add_location() WC Shipping Zone::add location code WC 10.3.3
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 );
}
}