WC_POS_APIv2_Coupons

POS Coupons Class duck punches the WC REST API.

Defined (1)

The class is defined in the following location(s).

/includes/apiv2/class-wc-pos-coupons.php  
  1. class WC_POS_APIv2_Coupons extends WC_POS_API_Abstract { 
  2.  
  3.  
  4. /** 
  5. */ 
  6. public function __construct() { 
  7. add_filter( 'woocommerce_rest_prepare_shop_coupon_object', array( $this, 'coupon_response' ), 10, 3 ); 
  8.  
  9.  
  10. /** 
  11. * @param WP_REST_Response $response The response object. 
  12. * @param WC_Data $coupon Object data. 
  13. * @param WP_REST_Request $request Request object. 
  14. * @return WP_REST_Response 
  15. */ 
  16. public function coupon_response( $response, $coupon, $request ) { 
  17. $data = $response->get_data(); 
  18.  
  19. // backwards compat 
  20. if( isset($data['date_modified']) ) { 
  21. $data['updated_at'] = $data['date_modified']; 
  22.  
  23. $response->set_data($data); 
  24. return $response; 
  25.  
  26.  
  27. /** 
  28. * Returns array of all coupon ids 
  29. * @param $date_modified 
  30. * @return array 
  31. */ 
  32. public function get_ids($date_modified) { 
  33. $args = array( 
  34. 'post_type' => array('shop_coupon'),  
  35. 'post_status' => array('publish'),  
  36. 'posts_per_page'=> -1,  
  37. 'fields' => 'ids' 
  38. ); 
  39.  
  40. if($date_modified) { 
  41. $args['date_query'][] = array( 
  42. 'column' => 'post_modified_gmt',  
  43. 'after' => $date_modified,  
  44. 'inclusive' => false 
  45. ); 
  46.  
  47. $query = new WP_Query( $args ); 
  48. return array_map( 'intval', $query->posts ); 
  49.