WJECF_Wrap_Product

The WooCommerce Extended Coupon Features WJECF Wrap Product class.

Defined (1)

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

/includes/wjecf-wc.php  
  1. class WJECF_Wrap_Product extends WJECF_Wrap { 
  2.  
  3. public function is_variation() { 
  4. return $this->object instanceof WC_Product_Variation; 
  5.  
  6. /** 
  7. * Retrieve the id of the product or the variation id if it's a variant. 
  8. *  
  9. * (2.4.0: Moved from WJECF_Controller to WJECF_WC) 
  10. *  
  11. * @param WC_Product $product  
  12. * @return int|bool The variation or product id. False if not a valid product 
  13. */ 
  14. public function get_product_or_variation_id() { 
  15. if ( $this->is_variation() ) { 
  16. return $this->get_variation_id(); 
  17. } elseif ( $this->object instanceof WC_Product ) { 
  18. return $this->get_id(); 
  19. } else { 
  20. return false; 
  21.  
  22. /** 
  23. * Retrieve the id of the parent product if it's a variation; otherwise retrieve this products id 
  24. *  
  25. * (2.4.0: Moved from WJECF_Controller to WJECF_WC) 
  26. *  
  27. * @param WC_Product $product  
  28. * @return int|bool The product id. False if this product is not a variation 
  29. */ 
  30. public function get_variable_product_id() { 
  31. if ( ! $this->is_variation() ) { 
  32. return false; 
  33.  
  34. if ( is_callable( array( $this->object, 'get_parent_id' ) ) ) { 
  35. return $this->object->get_parent_id(); 
  36. } else { 
  37. return wp_get_post_parent_id( $this->object->variation_id ); 
  38.  
  39. /** 
  40. * Get current variation id 
  41. * @return int|bool False if this is not a variation 
  42. */ 
  43. protected function get_variation_id() { 
  44. if ( ! $this->is_variation() ) { 
  45. return false; 
  46.  
  47. if ( is_callable( array( $this->object, 'get_id' ) ) ) { 
  48. //WP_CLI::log( "get_variation_id:WC27 " . get_class( $this->object ) ); 
  49. return $this->object->get_id();  
  50. } elseif ( is_callable( array( $this->object, 'get_variation_id' ) ) ) { 
  51. //WP_CLI::log( "get_variation_id:LEGACY " . get_class( $this->object ) ); 
  52. return $this->object->get_variation_id();  
  53. //WP_CLI::log( "get_variation_id:VERY OLD " . get_class( $this->object ) ); 
  54. return $this->object->variation_id; 
  55.  
  56.  
  57. public function get_name() { 
  58. if ( is_callable( array( $this->object, 'get_name' ) ) ) { 
  59. return $this->object->get_name(); 
  60. } else { 
  61. return $this->object->post->post_title; 
  62. }  
  63.  
  64. public function get_description() { 
  65. if ( is_callable( array( $this->object, 'get_description' ) ) ) { 
  66. return $this->object->get_description(); 
  67. } else { 
  68. return $this->object->post->post_content; 
  69.  
  70. public function get_short_description() { 
  71. if ( is_callable( array( $this->object, 'get_short_description' ) ) ) { 
  72. return $this->object->get_short_description(); 
  73. } else { 
  74. return $this->object->post->post_excerpt; 
  75.  
  76. public function get_tag_ids() { 
  77. if ( is_callable( array( $this->object, 'get_tag_ids' ) ) ) { 
  78. return $this->object->get_tag_ids(); 
  79. } else { 
  80. return $this->legacy_get_term_ids( 'product_tag' ); 
  81.  
  82. protected function legacy_get_term_ids( $taxonomy ) { 
  83. $terms = get_the_terms( $this->get_id(), $taxonomy ); 
  84. if ( false === $terms || is_wp_error( $terms ) ) { 
  85. return array(); 
  86. return wp_list_pluck( $terms, 'term_id' ); 
  87.