Skip to content

Commit 27e94f1

Browse files
Adds shipping zone locations support. (#10)
1 parent f85f833 commit 27e94f1

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,21 @@ $this->factory()->shipping_zone->create_and_get(
226226
);
227227
```
228228

229+
#### Adding locations
230+
231+
It's possible to add location rules to shipping zones. See the code below for an example:
232+
233+
```php
234+
$this->factory()->shipping_zone->set_zone_locations(
235+
1, array(
236+
array(
237+
'code' => '3024*',
238+
'type' => 'postcode',
239+
),
240+
)
241+
);
242+
```
243+
229244
### Shipping zone methods
230245

231246
You can access the shipping zone method factory by using `$this->factory()->shipping_zone_method` within a WooCommerce integration test.

src/Factories/ShippingZone.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,20 @@ public function get_object_by_id( $object_id ) {
6161
}
6262
return $shipping_zone;
6363
}
64+
65+
/**
66+
* Sets shipping zone locations.
67+
* @param int $object_id
68+
* @param array $data See https://woocommerce.github.io/woocommerce-rest-api-docs/?shell#update-a-locations-of-a-shipping-zone
69+
* @return int
70+
* @throws Exception
71+
*/
72+
public function set_zone_locations( $object_id, $data ) {
73+
$request = new \WP_REST_Request( 'PUT', '/wc/v3/shipping/zones/' . $object_id . '/locations' );
74+
$request->add_header( 'Content-Type', 'application/json' );
75+
$request->set_body( json_encode( $data ) ); //phpcs:ignore
76+
77+
$response = $this->do_request( $request );
78+
return $response->get_data()['id'];
79+
}
6480
}

0 commit comments

Comments
 (0)