WPOWCPDF_InvoicesCompatibilityData

WooCommerce data compatibility class.

Defined (1)

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

/includes/compatibility/abstract-wc-data-compatibility.php  
  1. abstract class Data { 
  2.  
  3. /** 
  4. * Creates aliases for add_meta_data, update_meta_data and delete_meta_data without the _data suffix 
  5. * @param string $name static function name 
  6. * @param array $arguments function arguments 
  7. */ 
  8. public static function __callStatic( $name, $arguments ) { 
  9. if ( substr( $name, -strlen('_meta') ) == '_meta' && method_exists( __CLASS__, $name.'_data' ) ) { 
  10. call_user_func_array( array( __CLASS__, $name.'_data' ), $arguments ); 
  11.  
  12.  
  13. /** 
  14. * Gets an object property. 
  15. * @since 4.6.0-dev 
  16. * @param \WC_Data $object the data object, likely \WC_Order or \WC_Product 
  17. * @param string $prop the property name 
  18. * @param string $context if 'view' then the value will be filtered 
  19. * @param array $compat_props Compatibility properties. 
  20. * @return mixed 
  21. */ 
  22. public static function get_prop( $object, $prop, $context = 'edit', $compat_props = array() ) { 
  23.  
  24. $value = ''; 
  25.  
  26. if ( WC_Core::is_wc_version_gte_3_0() ) { 
  27.  
  28. if ( is_callable( array( $object, "get_{$prop}" ) ) ) { 
  29. $value = $object->{"get_{$prop}"}( $context ); 
  30.  
  31. } else { 
  32.  
  33. // backport the property name 
  34. if ( isset( $compat_props[ $prop ] ) ) { 
  35. $prop = $compat_props[ $prop ]; 
  36.  
  37. // if this is the 'view' context and there is an accessor method, use it 
  38. if ( is_callable( array( $object, "get_{$prop}" ) ) && 'view' === $context ) { 
  39. $value = $object->{"get_{$prop}"}(); 
  40. } else { 
  41. $value = $object->$prop; 
  42.  
  43. return $value; 
  44.  
  45.  
  46. /** 
  47. * Sets an object's properties. 
  48. * Note that this does not save any data to the database. 
  49. * @since 4.6.0-dev 
  50. * @param \WC_Data $object the data object, likely \WC_Order or \WC_Product 
  51. * @param array $props the new properties as $key => $value 
  52. * @param array $compat_props Compatibility properties. 
  53. * @return \WC_Data 
  54. */ 
  55. public static function set_props( $object, $props, $compat_props = array() ) { 
  56.  
  57. if ( WC_Core::is_wc_version_gte_3_0() ) { 
  58.  
  59. $object->set_props( $props ); 
  60.  
  61. } else { 
  62.  
  63. foreach ( $props as $prop => $value ) { 
  64.  
  65. if ( isset( $compat_props[ $prop ] ) ) { 
  66. $prop = $compat_props[ $prop ]; 
  67.  
  68. $object->$prop = $value; 
  69.  
  70. return $object; 
  71.  
  72.  
  73. /** 
  74. * Gets an object's stored meta value. 
  75. * @since 4.6.0-dev 
  76. * @param \WC_Data $object the data object, likely \WC_Order or \WC_Product 
  77. * @param string $key the meta key 
  78. * @param bool $single whether to get the meta as a single item. Defaults to `true` 
  79. * @param string $context if 'view' then the value will be filtered 
  80. * @return mixed 
  81. */ 
  82. public static function get_meta( $object, $key = '', $single = true, $context = 'edit' ) { 
  83.  
  84. if ( WC_Core::is_wc_version_gte_3_0() ) { 
  85. $value = $object->get_meta( $key, $single, $context ); 
  86. } else { 
  87. $object_id = is_callable( array( $object, 'get_id' ) ) ? $object->get_id() : $object->id; 
  88. $value = get_post_meta( $object_id, $key, $single ); 
  89.  
  90. return $value; 
  91.  
  92.  
  93. /** 
  94. * Stores an object meta value. 
  95. * @since 4.6.0-dev 
  96. * @param \WC_Data $object the data object, likely \WC_Order or \WC_Product 
  97. * @param string $key the meta key 
  98. * @param string $value the meta value 
  99. * @param string $meta_id Optional. The specific meta ID to update 
  100. * @param bool $unique Optional. Whether the meta should be unique. 
  101. */ 
  102. public static function add_meta_data( $object, $key, $value, $unique = false ) { 
  103.  
  104. if ( WC_Core::is_wc_version_gte_3_0() ) { 
  105.  
  106. $object->add_meta_data( $key, $value, $unique ); 
  107.  
  108. $object->save_meta_data(); 
  109.  
  110. } else { 
  111.  
  112. $object_id = is_callable( array( $object, 'get_id' ) ) ? $object->get_id() : $object->id; 
  113. add_post_meta( $object_id, $key, $value, $unique ); 
  114.  
  115.  
  116. /** 
  117. * Updates an object's stored meta value. 
  118. * @since 4.6.0-dev 
  119. * @param \WC_Data $object the data object, likely \WC_Order or \WC_Product 
  120. * @param string $key the meta key 
  121. * @param string $value the meta value 
  122. * @param int|strint $meta_id Optional. The specific meta ID to update 
  123. */ 
  124. public static function update_meta_data( $object, $key, $value, $meta_id = '' ) { 
  125.  
  126. if ( WC_Core::is_wc_version_gte_3_0() ) { 
  127.  
  128. $object->update_meta_data( $key, $value, $meta_id ); 
  129.  
  130. $object->save_meta_data(); 
  131.  
  132. } else { 
  133.  
  134. $object_id = is_callable( array( $object, 'get_id' ) ) ? $object->get_id() : $object->id; 
  135. update_post_meta( $object_id, $key, $value ); 
  136.  
  137.  
  138. /** 
  139. * Deletes an object's stored meta value. 
  140. * @since 4.6.0-dev 
  141. * @param \WC_Data $object the data object, likely \WC_Order or \WC_Product 
  142. * @param string $key the meta key 
  143. */ 
  144. public static function delete_meta_data( $object, $key ) { 
  145.  
  146. if ( WC_Core::is_wc_version_gte_3_0() ) { 
  147.  
  148. $object->delete_meta_data( $key ); 
  149.  
  150. $object->save_meta_data(); 
  151.  
  152. } else { 
  153.  
  154. $object_id = is_callable( array( $object, 'get_id' ) ) ? $object->get_id() : $object->id; 
  155. delete_post_meta( $object_id, $key ); 
  156.  
  157.