WC_Order_Item_Coupon

Order Line Item (coupon).

Defined (1)

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

/includes/class-wc-order-item-coupon.php  
  1. class WC_Order_Item_Coupon extends WC_Order_Item { 
  2.  
  3. /** 
  4. * Order Data array. This is the core order data exposed in APIs since 3.0.0. 
  5. * @since 3.0.0 
  6. * @var array 
  7. */ 
  8. protected $extra_data = array( 
  9. 'code' => '',  
  10. 'discount' => 0,  
  11. 'discount_tax' => 0,  
  12. ); 
  13.  
  14. /** 
  15. |-------------------------------------------------------------------------- 
  16. | Setters 
  17. |-------------------------------------------------------------------------- 
  18. */ 
  19.  
  20. /** 
  21. * Set order item name. 
  22. * @param string $value 
  23. * @throws WC_Data_Exception 
  24. */ 
  25. public function set_name( $value ) { 
  26. return $this->set_code( $value ); 
  27.  
  28. /** 
  29. * Set code. 
  30. * @param string $value 
  31. * @throws WC_Data_Exception 
  32. */ 
  33. public function set_code( $value ) { 
  34. $this->set_prop( 'code', wc_clean( $value ) ); 
  35.  
  36. /** 
  37. * Set discount amount. 
  38. * @param string $value 
  39. * @throws WC_Data_Exception 
  40. */ 
  41. public function set_discount( $value ) { 
  42. $this->set_prop( 'discount', wc_format_decimal( $value ) ); 
  43.  
  44. /** 
  45. * Set discounted tax amount. 
  46. * @param string $value 
  47. * @throws WC_Data_Exception 
  48. */ 
  49. public function set_discount_tax( $value ) { 
  50. $this->set_prop( 'discount_tax', wc_format_decimal( $value ) ); 
  51.  
  52. /** 
  53. |-------------------------------------------------------------------------- 
  54. | Getters 
  55. |-------------------------------------------------------------------------- 
  56. */ 
  57.  
  58. /** 
  59. * Get order item type. 
  60. * @return string 
  61. */ 
  62. public function get_type() { 
  63. return 'coupon'; 
  64.  
  65. /** 
  66. * Get order item name. 
  67. * @param string $context 
  68. * @return string 
  69. */ 
  70. public function get_name( $context = 'view' ) { 
  71. return $this->get_code( $context ); 
  72.  
  73. /** 
  74. * Get coupon code. 
  75. * @param string $context 
  76. * @return string 
  77. */ 
  78. public function get_code( $context = 'view' ) { 
  79. return $this->get_prop( 'code', $context ); 
  80.  
  81. /** 
  82. * Get discount amount. 
  83. * @param string $context 
  84. * @return string 
  85. */ 
  86. public function get_discount( $context = 'view' ) { 
  87. return $this->get_prop( 'discount', $context ); 
  88.  
  89. /** 
  90. * Get discounted tax amount. 
  91. * @return string 
  92. */ 
  93. public function get_discount_tax( $context = 'view' ) { 
  94. return $this->get_prop( 'discount_tax', $context ); 
  95.  
  96. /** 
  97. |-------------------------------------------------------------------------- 
  98. | Array Access Methods 
  99. |-------------------------------------------------------------------------- 
  100. | For backwards compat with legacy arrays. 
  101. */ 
  102.  
  103. /** 
  104. * offsetGet for ArrayAccess/Backwards compatibility. 
  105. * @deprecated Add deprecation notices in future release. 
  106. * @param string $offset 
  107. * @return mixed 
  108. */ 
  109. public function offsetGet( $offset ) { 
  110. if ( 'discount_amount' === $offset ) { 
  111. $offset = 'discount'; 
  112. } elseif ( 'discount_amount_tax' === $offset ) { 
  113. $offset = 'discount_tax'; 
  114. return parent::offsetGet( $offset ); 
  115.  
  116. /** 
  117. * offsetSet for ArrayAccess/Backwards compatibility. 
  118. * @deprecated Add deprecation notices in future release. 
  119. * @param string $offset 
  120. * @param mixed $value 
  121. */ 
  122. public function offsetSet( $offset, $value ) { 
  123. if ( 'discount_amount' === $offset ) { 
  124. $offset = 'discount'; 
  125. } elseif ( 'discount_amount_tax' === $offset ) { 
  126. $offset = 'discount_tax'; 
  127. parent::offsetSet( $offset, $value ); 
  128.  
  129. /** 
  130. * offsetExists for ArrayAccess 
  131. * @param string $offset 
  132. * @return bool 
  133. */ 
  134. public function offsetExists( $offset ) { 
  135. if ( in_array( $offset, array( 'discount_amount', 'discount_amount_tax' ) ) ) { 
  136. return true; 
  137. return parent::offsetExists( $offset );