Overview
  • Namespace
  • Class

Namespaces

  • None
  • WC_POS
    • Admin
      • Settings
        • Receipt
    • API
    • Gateways
    • Integrations
    • Products

Classes

  • WC_POS\Activator
  • WC_POS\Admin
  • WC_POS\Admin\Gateways
  • WC_POS\Admin\Menu
  • WC_POS\Admin\Notices
  • WC_POS\Admin\Orders
  • WC_POS\Admin\Page
  • WC_POS\Admin\Permalink
  • WC_POS\Admin\Plugins
  • WC_POS\Admin\Products
  • WC_POS\Admin\Settings
  • WC_POS\Admin\Settings\Access
  • WC_POS\Admin\Settings\Checkout
  • WC_POS\Admin\Settings\Customers
  • WC_POS\Admin\Settings\Gateways
  • WC_POS\Admin\Settings\General
  • WC_POS\Admin\Settings\HotKeys
  • WC_POS\Admin\Settings\Page
  • WC_POS\Admin\Settings\Receipt\Options
  • WC_POS\Admin\Settings\Receipt\Template
  • WC_POS\Admin\Settings\Receipts
  • WC_POS\Admin\Settings\Status
  • WC_POS\Admin\Settings\Tools
  • WC_POS\Admin\Status
  • WC_POS\Ajax
  • WC_POS\API
  • WC_POS\API\Coupons
  • WC_POS\API\Customers
  • WC_POS\API\Gateways
  • WC_POS\API\i18n
  • WC_POS\API\Orders
  • WC_POS\API\Params
  • WC_POS\API\Payload
  • WC_POS\API\Products
  • WC_POS\API\Settings
  • WC_POS\API\Support
  • WC_POS\API\Templates
  • WC_POS\Customers
  • WC_POS\Deactivator
  • WC_POS\Gateways
  • WC_POS\Gateways\Card
  • WC_POS\Gateways\Cash
  • WC_POS\i18n
  • WC_POS\Integrations\Bookings
  • WC_POS\Products
  • WC_POS\Products\Visibility
  • WC_POS\Setup
  • WC_POS\Status
  • WC_POS\Tax
  • WC_POS\Template

Functions

  • is_pos
  • is_pos_admin
  • wc_pos_get_option
  • wc_pos_json_encode
  • wc_pos_locate_template
  • wc_pos_trim_html_string
  • wc_pos_update_option
  • wc_pos_url
 1 <?php
 2 
 3 /**
 4  * POS Coupons Class
 5  * duck punches the WC REST API
 6  *
 7  * @class    WC_POS_API_Coupons
 8  * @package  WooCommerce POS
 9  * @author   Paul Kilmurray <paul@kilbot.com.au>
10  * @link     http://www.woopos.com.au
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   /** @var string $base the route base */
21   protected $base = '/coupons';
22 
23   /**
24    * Register routes for POS Coupons
25    *
26    * @param array $routes
27    * @return array
28    */
29   public function register_routes( $routes ) {
30 
31     # GET /coupons/ids
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    * Returns array of all coupon ids
42    *
43    * @param array $filter
44    * @return array|void
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    * @param $id
70    * @return array
71    */
72   private function format_id( $id ) {
73     return array( 'id' => $id );
74   }
75 
76 }
API documentation generated by ApiGen