WC_Legacy_Coupon

Legacy Coupon.

Defined (1)

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

/includes/legacy/class-wc-legacy-coupon.php  
  1. abstract class WC_Legacy_Coupon extends WC_Data { 
  2.  
  3. /** 
  4. * Magic __isset method for backwards compatibility. Legacy properties which could be accessed directly in the past. 
  5. * @param string $key 
  6. * @return bool 
  7. */ 
  8. public function __isset( $key ) { 
  9. $legacy_keys = array( 
  10. 'id',  
  11. 'exists',  
  12. 'coupon_custom_fields',  
  13. 'type',  
  14. 'discount_type',  
  15. 'amount',  
  16. 'coupon_amount',  
  17. 'code',  
  18. 'individual_use',  
  19. 'product_ids',  
  20. 'exclude_product_ids',  
  21. 'usage_limit',  
  22. 'usage_limit_per_user',  
  23. 'limit_usage_to_x_items',  
  24. 'usage_count',  
  25. 'expiry_date',  
  26. 'product_categories',  
  27. 'exclude_product_categories',  
  28. 'minimum_amount',  
  29. 'maximum_amount',  
  30. 'customer_email',  
  31. ); 
  32. if ( in_array( $key, $legacy_keys ) ) { 
  33. return true; 
  34. return false; 
  35.  
  36. /** 
  37. * Magic __get method for backwards compatibility. Maps legacy vars to new getters. 
  38. * @param string $key 
  39. * @return mixed 
  40. */ 
  41. public function __get( $key ) { 
  42. wc_doing_it_wrong( $key, 'Coupon properties should not be accessed directly.', '3.0' ); 
  43.  
  44. switch ( $key ) { 
  45. case 'id' : 
  46. $value = $this->get_id(); 
  47. break; 
  48. case 'exists' : 
  49. $value = ( $this->get_id() > 0 ) ? true : false; 
  50. break; 
  51. case 'coupon_custom_fields' : 
  52. $legacy_custom_fields = array(); 
  53. $custom_fields = $this->get_id() ? $this->get_meta_data() : array(); 
  54. if ( ! empty( $custom_fields ) ) { 
  55. foreach ( $custom_fields as $cf_value ) { 
  56. // legacy only supports 1 key 
  57. $legacy_custom_fields[ $cf_value->key ][0] = $cf_value->value; 
  58. $value = $legacy_custom_fields; 
  59. break; 
  60. case 'type' : 
  61. case 'discount_type' : 
  62. $value = $this->get_discount_type(); 
  63. break; 
  64. case 'amount' : 
  65. case 'coupon_amount' : 
  66. $value = $this->get_amount(); 
  67. break; 
  68. case 'code' : 
  69. $value = $this->get_code(); 
  70. break; 
  71. case 'individual_use' : 
  72. $value = ( true === $this->get_individual_use() ) ? 'yes' : 'no'; 
  73. break; 
  74. case 'product_ids' : 
  75. $value = $this->get_product_ids(); 
  76. break; 
  77. case 'exclude_product_ids' : 
  78. $value = $this->get_excluded_product_ids(); 
  79. break; 
  80. case 'usage_limit' : 
  81. $value = $this->get_usage_limit(); 
  82. break; 
  83. case 'usage_limit_per_user' : 
  84. $value = $this->get_usage_limit_per_user(); 
  85. break; 
  86. case 'limit_usage_to_x_items' : 
  87. $value = $this->get_limit_usage_to_x_items(); 
  88. break; 
  89. case 'usage_count' : 
  90. $value = $this->get_usage_count(); 
  91. break; 
  92. case 'expiry_date' : 
  93. $value = ( $this->get_date_expires() ? $this->get_date_expires()->date( 'Y-m-d' ) : '' ); 
  94. break; 
  95. case 'product_categories' : 
  96. $value = $this->get_product_categories(); 
  97. break; 
  98. case 'exclude_product_categories' : 
  99. $value = $this->get_excluded_product_categories(); 
  100. break; 
  101. case 'minimum_amount' : 
  102. $value = $this->get_minimum_amount(); 
  103. break; 
  104. case 'maximum_amount' : 
  105. $value = $this->get_maximum_amount(); 
  106. break; 
  107. case 'customer_email' : 
  108. $value = $this->get_email_restrictions(); 
  109. break; 
  110. default : 
  111. $value = ''; 
  112. break; 
  113.  
  114. return $value; 
  115.  
  116. /** 
  117. * Format loaded data as array. 
  118. * @param string|array $array 
  119. * @return array 
  120. */ 
  121. public function format_array( $array ) { 
  122. wc_deprecated_function( 'WC_Coupon::format_array', '3.0' ); 
  123. if ( ! is_array( $array ) ) { 
  124. if ( is_serialized( $array ) ) { 
  125. $array = maybe_unserialize( $array ); 
  126. } else { 
  127. $array = explode( ', ', $array ); 
  128. return array_filter( array_map( 'trim', array_map( 'strtolower', $array ) ) ); 
  129.  
  130.  
  131. /** 
  132. * Check if coupon needs applying before tax. 
  133. * @return bool 
  134. */ 
  135. public function apply_before_tax() { 
  136. wc_deprecated_function( 'WC_Coupon::apply_before_tax', '3.0' ); 
  137. return true; 
  138.  
  139. /** 
  140. * Check if a coupon enables free shipping. 
  141. * @return bool 
  142. */ 
  143. public function enable_free_shipping() { 
  144. wc_deprecated_function( 'WC_Coupon::enable_free_shipping', '3.0', 'WC_Coupon::get_free_shipping' ); 
  145. return $this->get_free_shipping(); 
  146.  
  147. /** 
  148. * Check if a coupon excludes sale items. 
  149. * @return bool 
  150. */ 
  151. public function exclude_sale_items() { 
  152. wc_deprecated_function( 'WC_Coupon::exclude_sale_items', '3.0', 'WC_Coupon::get_exclude_sale_items' ); 
  153. return $this->get_exclude_sale_items(); 
  154.  
  155. /** 
  156. * Increase usage count for current coupon. 
  157. * @param string $used_by Either user ID or billing email 
  158. */ 
  159. public function inc_usage_count( $used_by = '' ) { 
  160. $this->increase_usage_count( $used_by ); 
  161.  
  162. /** 
  163. * Decrease usage count for current coupon. 
  164. * @param string $used_by Either user ID or billing email 
  165. */ 
  166. public function dcr_usage_count( $used_by = '' ) { 
  167. $this->decrease_usage_count( $used_by );