WJECF_Wrap

The WooCommerce Extended Coupon Features WJECF Wrap class.

Defined (1)

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

/includes/wjecf-wc.php  
  1. class WJECF_Wrap { 
  2. protected $object = null; 
  3.  
  4. public function __construct( $object ) { 
  5. $this->object = $object; 
  6. //error_log('Wrapping ' . get_class( $object ) ); 
  7.  
  8. public function get_id() { 
  9. //Since WC 2.7 
  10. if ( is_callable( array( $this->object, 'get_id' ) ) ) { 
  11. return $this->object->get_id(); 
  12. return $this->object->id; 
  13.  
  14. public function holds( $object ) { 
  15. return $object === $this->object; 
  16.  
  17. /** 
  18. * Get Meta Data by Key. 
  19. * @since 2.4.0 
  20. * @param string $key 
  21. * @param bool $single return first found meta, or all 
  22. * @return mixed 
  23. */ 
  24. public function get_meta( $meta_key, $single = true ) { 
  25. if ( is_callable( array( $this->object, 'get_meta' ) ) ) {  
  26. return $this->get_meta_wc27( $meta_key, $single ); 
  27.  
  28. return $this->get_meta_legacy( $meta_key, $single ); 
  29.  
  30. //return get_post_meta( $this->object->id, $meta_key, $single ); 
  31. //If no value found:  
  32. //If $single is true, an empty string is returned. 
  33. //If $single is false, an empty array is returned. 
  34.  
  35. protected function get_meta_wc27( $meta_key, $single = true ) { 
  36. $values = $this->object->get_meta( $meta_key, $single ); 
  37. if ($single) { 
  38. return $values; //it's just one, dispite the plural in the name! 
  39.  
  40. if ( $values === '' ) { 
  41. return array(); //get_meta returns empty string if meta does not exist 
  42.  
  43. return wp_list_pluck( array_values( $values ), 'value' ); //when not using array_values; the index might not start with 0 
  44.  
  45. protected $meta_cache = array(); 
  46.  
  47. protected function get_meta_legacy( $meta_key, $single = true ) { 
  48. throw new Exception( sprintf( '%s::get_meta_legacy not implemented', get_class( $this ) ) ); 
  49.