1 <?php
2
3 4 5 6 7 8 9 10 11
12
13 namespace WC_POS\API;
14
15 use WC_API_Resource;
16 use WC_API_Server;
17
18 class Coupons extends WC_API_Resource {
19
20
21 protected $base = '/coupons';
22
23 24 25 26 27 28
29 public function register_routes( $routes ) {
30
31
32 $routes[ $this->base . '/ids'] = array(
33 array( array( $this, 'get_all_ids' ), WC_API_Server::READABLE ),
34 );
35
36 return $routes;
37 }
38
39
40 41 42 43 44 45
46 public function get_all_ids( $filter = array() ) {
47 $args = array(
48 'post_type' => array( 'shop_coupon' ),
49 'post_status' => array( 'publish' ),
50 'posts_per_page' => -1,
51 'fields' => 'ids'
52 );
53
54 if ( isset( $filter[ 'updated_at_min' ] ) ) {
55 $args[ 'date_query' ][] = array(
56 'column' => 'post_modified_gmt',
57 'after' => $filter[ 'updated_at_min' ],
58 'inclusive' => false
59 );
60 }
61
62 $query = new \WP_Query( $args );
63 $this->server->add_pagination_headers($query);
64 return array_map( array( $this, 'format_id' ), $query->posts );
65 }
66
67
68 69 70 71
72 private function format_id( $id ) {
73 return array( 'id' => $id );
74 }
75
76 }