WPOWCPDF_InvoicesCompatibilityProduct

WooCommerce product compatibility class.

Defined (1)

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

/includes/compatibility/class-wc-product-compatibility.php  
  1. class Product extends Data { 
  2.  
  3.  
  4. /** @var array mapped compatibility properties, as `$new_prop => $old_prop` */ 
  5. protected static $compat_props = array( 
  6. 'catalog_visibility' => 'visibility',  
  7. 'date_on_sale_from' => 'sale_price_dates_from',  
  8. 'date_on_sale_to' => 'sale_price_dates_to',  
  9. 'gallery_image_ids' => 'product_image_gallery',  
  10. 'cross_sell_ids' => 'crosssell_ids',  
  11. ); 
  12.  
  13.  
  14. /** 
  15. * Backports WC_Product::get_id() method to 2.4.x 
  16. * @link https://github.com/woothemes/woocommerce/pull/9765 
  17. * @since 4.2.0 
  18. * @param \WC_Product $product product object 
  19. * @return string|int product ID 
  20. */ 
  21. public static function get_id( \WC_Product $product ) { 
  22.  
  23. if ( self::is_wc_version_gte_2_5() ) { 
  24.  
  25. return $product->get_id(); 
  26.  
  27. } else { 
  28.  
  29. return $product->is_type( 'variation' ) ? $product->variation_id : $product->id; 
  30.  
  31.  
  32. /** 
  33. * Gets a product property. 
  34. * @since 4.6.0-dev 
  35. * @param \WC_Product $object the product object 
  36. * @param string $prop the property name 
  37. * @param string $context if 'view' then the value will be filtered 
  38. * @return mixed 
  39. */ 
  40. public static function get_prop( $object, $prop, $context = 'edit', $compat_props = array() ) { 
  41.  
  42. // backport 'WC_Product::get_parent_id()' to pre-3.0 
  43. if ( WC_Core::is_wc_version_lt_3_0() && 'parent_id' === $prop ) { 
  44. $prop = 'id'; 
  45. $context = $object->is_type( 'variation' ) ? 'raw' : $context; 
  46.  
  47. return parent::get_prop( $object, $prop, $context, self::$compat_props ); 
  48.  
  49.  
  50. /** 
  51. * Sets an products's properties. 
  52. * Note that this does not save any data to the database. 
  53. * @since 4.6.0-dev 
  54. * @param \WC_Product $object the product object 
  55. * @param array $props the new properties as $key => $value 
  56. * @return \WC_Product 
  57. */ 
  58. public static function set_props( $object, $props, $compat_props = array() ) { 
  59.  
  60. return parent::set_props( $object, $props, self::$compat_props ); 
  61.  
  62.  
  63. /** 
  64. * Makes WC_Product::get_parent() available for WC 3.0+ 
  65. * @since 4.6.0-dev 
  66. * @param \WC_Product $product the product object 
  67. * @return \WC_Product 
  68. */ 
  69. public static function get_parent( \WC_Product $product ) { 
  70.  
  71. if ( WC_Core::is_wc_version_gte_3_0() ) { 
  72. $parent = wc_get_product( $product->get_parent_id() ); 
  73. } else { 
  74. $parent = $product->get_parent(); 
  75.  
  76. return $parent; 
  77.  
  78.  
  79.  
  80. /** 
  81. * Makes WC_Product::get_dimensions() available for WC 3.0+ 
  82. * @since 4.6.0-dev 
  83. * @param \WC_Product $product the product object 
  84. * @param string $rating Optional. The product rating 
  85. * @return string 
  86. */ 
  87. public static function get_dimensions( \WC_Product $product ) { 
  88.  
  89. if ( WC_Core::is_wc_version_gte_3_0() ) { 
  90. $dimensions = array( 
  91. 'length' => $product->get_length(),  
  92. 'width' => $product->get_width(),  
  93. 'height' => $product->get_height(),  
  94. ); 
  95. return apply_filters( 'woocommerce_product_dimensions', wc_format_dimensions( $dimensions ), $product ); 
  96. } else { 
  97. return $product->get_dimensions(); 
  98.  
  99.  
  100. /** 
  101. * Backports wc_update_product_stock() to pre-3.0.0 
  102. * @since 4.6.0-dev 
  103. * @param \WC_Product $product the product object 
  104. * @param int $amount Optional. The new stock quantity 
  105. * @param string $mode Optional. Can be set, add, or subtract 
  106. * @return int 
  107. */ 
  108. public static function wc_update_product_stock( \WC_Product $product, $amount = null, $mode = 'set' ) { 
  109.  
  110. if ( WC_Core::is_wc_version_gte_3_0() ) { 
  111. return wc_update_product_stock( $product, $amount, $mode ); 
  112. } else { 
  113. return $product->set_stock( $amount, $mode ); 
  114.  
  115.  
  116. /** 
  117. * Backports wc_get_price_html_from_text() to pre-3.0.0 
  118. * @since 4.6.0-dev 
  119. * @param \WC_Product $product the product object 
  120. * @return string 
  121. */ 
  122. public static function wc_get_price_html_from_text( \WC_Product $product ) { 
  123.  
  124. if ( WC_Core::is_wc_version_gte_3_0() ) { 
  125. return wc_get_price_html_from_text(); 
  126. } else { 
  127. return $product->get_price_html_from_text(); 
  128.  
  129.  
  130. /** 
  131. * Backports wc_get_price_including_tax() to pre-3.0.0 
  132. * @since 4.6.0-dev 
  133. * @param \WC_Product $product the product object 
  134. * @param int $qty Optional. The quantity 
  135. * @param string $price Optional. The product price 
  136. * @return string 
  137. */ 
  138. public static function wc_get_price_including_tax( \WC_Product $product, $qty = 1, $price = '' ) { 
  139.  
  140. if ( WC_Core::is_wc_version_gte_3_0() ) { 
  141.  
  142. return wc_get_price_including_tax( $product, array( 
  143. 'qty' => $qty,  
  144. 'price' => $price,  
  145. ) ); 
  146.  
  147. } else { 
  148.  
  149. return $product->get_price_including_tax( $qty, $price ); 
  150.  
  151.  
  152. /** 
  153. * Backports wc_get_price_excluding_tax() to pre-3.0.0 
  154. * @since 4.6.0-dev 
  155. * @param \WC_Product $product the product object 
  156. * @param int $qty Optional. The quantity 
  157. * @param string $price Optional. The product price 
  158. * @return string 
  159. */ 
  160. public static function wc_get_price_excluding_tax( \WC_Product $product, $qty = 1, $price = '' ) { 
  161.  
  162. if ( WC_Core::is_wc_version_gte_3_0() ) { 
  163.  
  164. return wc_get_price_excluding_tax( $product, array( 
  165. 'qty' => $qty,  
  166. 'price' => $price,  
  167. ) ); 
  168.  
  169. } else { 
  170.  
  171. return $product->get_price_excluding_tax( $qty, $price ); 
  172.  
  173.  
  174. /** 
  175. * Backports wc_get_price_to_display() to pre-3.0.0 
  176. * @since 4.6.0-dev 
  177. * @param \WC_Product $product the product object 
  178. * @param string $price Optional. The product price 
  179. * @param int $qty Optional. The quantity 
  180. * @return string 
  181. */ 
  182. public static function wc_get_price_to_display( \WC_Product $product, $price = '', $qty = 1 ) { 
  183.  
  184. if ( WC_Core::is_wc_version_gte_3_0() ) { 
  185.  
  186. return wc_get_price_to_display( $product, array( 
  187. 'qty' => $qty,  
  188. 'price' => $price,  
  189. ) ); 
  190.  
  191. } else { 
  192.  
  193. return $product->get_display_price( $price, $qty ); 
  194.  
  195.  
  196. /** 
  197. * Backports wc_get_product_category_list() to pre-3.0.0 
  198. * @since 4.6.0-dev 
  199. * @param \WC_Product $product the product object 
  200. * @param string $sep Optional. The list separator 
  201. * @param string $before Optional. To display before the list 
  202. * @param string $after Optional. To display after the list 
  203. * @return string 
  204. */ 
  205. public static function wc_get_product_category_list( \WC_Product $product, $sep = ', ', $before = '', $after = '' ) { 
  206.  
  207. if ( WC_Core::is_wc_version_gte_3_0() ) { 
  208.  
  209. $id = $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id(); 
  210.  
  211. return wc_get_product_category_list( $id, $sep, $before, $after ); 
  212.  
  213. } else { 
  214.  
  215. return $product->get_categories( $sep, $before, $after ); 
  216.  
  217.  
  218. /** 
  219. * Backports wc_get_rating_html() to pre-3.0.0 
  220. * @since 4.6.0-dev 
  221. * @param \WC_Product $product the product object 
  222. * @param string $rating Optional. The product rating 
  223. * @return string 
  224. */ 
  225. public static function wc_get_rating_html( \WC_Product $product, $rating = null ) { 
  226.  
  227. if ( WC_Core::is_wc_version_gte_3_0() ) { 
  228. return wc_get_rating_html( $rating ); 
  229. } else { 
  230. return $product->get_rating_html( $rating ); 
  231.