/includes/legacy/abstract-wc-legacy-product.php

  1. <?php 
  2. if ( ! defined( 'ABSPATH' ) ) { 
  3. exit; 
  4.  
  5. /** 
  6. * Legacy Abstract Product 
  7. * 
  8. * Legacy and deprecated functions are here to keep the WC_Abstract_Product 
  9. * clean. 
  10. * This class will be removed in future versions. 
  11. * 
  12. * @version 3.0.0 
  13. * @package WooCommerce/Abstracts 
  14. * @category Abstract Class 
  15. * @author WooThemes 
  16. */ 
  17. abstract class WC_Abstract_Legacy_Product extends WC_Data { 
  18.  
  19. /** 
  20. * Magic __isset method for backwards compatibility. Legacy properties which could be accessed directly in the past. 
  21. * 
  22. * @param string $key Key name. 
  23. * @return bool 
  24. */ 
  25. public function __isset( $key ) { 
  26. $valid = array( 
  27. 'id',  
  28. 'product_attributes',  
  29. 'visibility',  
  30. 'sale_price_dates_from',  
  31. 'sale_price_dates_to',  
  32. 'post',  
  33. 'download_type',  
  34. 'product_image_gallery',  
  35. 'variation_shipping_class',  
  36. 'shipping_class',  
  37. 'total_stock',  
  38. 'crosssell_ids',  
  39. 'parent',  
  40. ); 
  41. if ( $this->is_type( 'variation' ) ) { 
  42. $valid = array_merge( $valid, array( 
  43. 'variation_id',  
  44. 'variation_data',  
  45. 'variation_has_stock',  
  46. 'variation_shipping_class_id',  
  47. 'variation_has_sku',  
  48. 'variation_has_length',  
  49. 'variation_has_width',  
  50. 'variation_has_height',  
  51. 'variation_has_weight',  
  52. 'variation_has_tax_class',  
  53. 'variation_has_downloadable_files',  
  54. ) ); 
  55. return in_array( $key, array_merge( $valid, array_keys( $this->data ) ) ) || metadata_exists( 'post', $this->get_id(), '_' . $key ) || metadata_exists( 'post', $this->get_parent_id(), '_' . $key ); 
  56.  
  57. /** 
  58. * Magic __get method for backwards compatibility. Maps legacy vars to new getters. 
  59. * 
  60. * @param string $key Key name. 
  61. * @return mixed 
  62. */ 
  63. public function __get( $key ) { 
  64.  
  65. if ( 'post_type' === $key ) { 
  66. return $this->post_type; 
  67.  
  68. wc_doing_it_wrong( $key, __( 'Product properties should not be accessed directly.', 'woocommerce' ), '3.0' ); 
  69.  
  70. switch ( $key ) { 
  71. case 'id' : 
  72. $value = $this->is_type( 'variation' ) ? $this->get_parent_id() : $this->get_id(); 
  73. break; 
  74. case 'product_type' : 
  75. $value = $this->get_type(); 
  76. break; 
  77. case 'product_attributes' : 
  78. $value = isset( $this->data['attributes'] ) ? $this->data['attributes'] : ''; 
  79. break; 
  80. case 'visibility' : 
  81. $value = $this->get_catalog_visibility(); 
  82. break; 
  83. case 'sale_price_dates_from' : 
  84. return $this->get_date_on_sale_from() ? $this->get_date_on_sale_from()->getTimestamp() : ''; 
  85. break; 
  86. case 'sale_price_dates_to' : 
  87. return $this->get_date_on_sale_to() ? $this->get_date_on_sale_to()->getTimestamp() : ''; 
  88. break; 
  89. case 'post' : 
  90. $value = get_post( $this->get_id() ); 
  91. break; 
  92. case 'download_type' : 
  93. return 'standard'; 
  94. break; 
  95. case 'product_image_gallery' : 
  96. $value = $this->get_gallery_image_ids(); 
  97. break; 
  98. case 'variation_shipping_class' : 
  99. case 'shipping_class' : 
  100. $value = $this->get_shipping_class(); 
  101. break; 
  102. case 'total_stock' : 
  103. $value = $this->get_total_stock(); 
  104. break; 
  105. case 'downloadable' : 
  106. case 'virtual' : 
  107. case 'manage_stock' : 
  108. case 'featured' : 
  109. case 'sold_individually' : 
  110. $value = $this->{"get_$key"}() ? 'yes' : 'no'; 
  111. break; 
  112. case 'crosssell_ids' : 
  113. $value = $this->get_cross_sell_ids(); 
  114. break; 
  115. case 'upsell_ids' : 
  116. $value = $this->get_upsell_ids(); 
  117. break; 
  118. case 'parent' : 
  119. $value = wc_get_product( $this->get_parent_id() ); 
  120. break; 
  121. case 'variation_id' : 
  122. $value = $this->is_type( 'variation' ) ? $this->get_id() : ''; 
  123. break; 
  124. case 'variation_data' : 
  125. $value = $this->is_type( 'variation' ) ? wc_get_product_variation_attributes( $this->get_id() ) : ''; 
  126. break; 
  127. case 'variation_has_stock' : 
  128. $value = $this->is_type( 'variation' ) ? $this->managing_stock() : ''; 
  129. break; 
  130. case 'variation_shipping_class_id' : 
  131. $value = $this->is_type( 'variation' ) ? $this->get_shipping_class_id() : ''; 
  132. break; 
  133. case 'variation_has_sku' : 
  134. case 'variation_has_length' : 
  135. case 'variation_has_width' : 
  136. case 'variation_has_height' : 
  137. case 'variation_has_weight' : 
  138. case 'variation_has_tax_class' : 
  139. case 'variation_has_downloadable_files' : 
  140. $value = true; // These were deprecated in 2.2 and simply returned true in 2.6.x. 
  141. break; 
  142. default : 
  143. if ( in_array( $key, array_keys( $this->data ) ) ) { 
  144. $value = $this->{"get_$key"}(); 
  145. } else { 
  146. $value = get_post_meta( $this->id, '_' . $key, true ); 
  147. break; 
  148. return $value; 
  149.  
  150. /** 
  151. * If set, get the default attributes for a variable product. 
  152. * 
  153. * @deprecated 3.0.0 
  154. * @return array 
  155. */ 
  156. public function get_variation_default_attributes() { 
  157. wc_deprecated_function( 'WC_Product_Variable::get_variation_default_attributes', '3.0', 'WC_Product::get_default_attributes' ); 
  158. return apply_filters( 'woocommerce_product_default_attributes', $this->get_default_attributes(), $this ); 
  159.  
  160. /** 
  161. * Returns the gallery attachment ids. 
  162. * 
  163. * @deprecated 3.0.0 
  164. * @return array 
  165. */ 
  166. public function get_gallery_attachment_ids() { 
  167. wc_deprecated_function( 'WC_Product::get_gallery_attachment_ids', '3.0', 'WC_Product::get_gallery_image_ids' ); 
  168. return $this->get_gallery_image_ids(); 
  169.  
  170. /** 
  171. * Set stock level of the product. 
  172. * 
  173. * @deprecated 3.0.0 
  174. */ 
  175. public function set_stock( $amount = null, $mode = 'set' ) { 
  176. wc_deprecated_function( 'WC_Product::set_stock', '3.0', 'wc_update_product_stock' ); 
  177. return wc_update_product_stock( $this, $amount, $mode ); 
  178.  
  179. /** 
  180. * Reduce stock level of the product. 
  181. * 
  182. * @deprecated 3.0.0 
  183. * @param int $amount Amount to reduce by. Default: 1 
  184. * @return int new stock level 
  185. */ 
  186. public function reduce_stock( $amount = 1 ) { 
  187. wc_deprecated_function( 'WC_Product::reduce_stock', '3.0', 'wc_update_product_stock' ); 
  188. return wc_update_product_stock( $this, $amount, 'decrease' ); 
  189.  
  190. /** 
  191. * Increase stock level of the product. 
  192. * 
  193. * @deprecated 3.0.0 
  194. * @param int $amount Amount to increase by. Default 1. 
  195. * @return int new stock level 
  196. */ 
  197. public function increase_stock( $amount = 1 ) { 
  198. wc_deprecated_function( 'WC_Product::increase_stock', '3.0', 'wc_update_product_stock' ); 
  199. return wc_update_product_stock( $this, $amount, 'increase' ); 
  200.  
  201. /** 
  202. * Check if the stock status needs changing. 
  203. * 
  204. * @deprecated 3.0.0 Sync is done automatically on read/save, so calling this should not be needed any more. 
  205. */ 
  206. public function check_stock_status() { 
  207. wc_deprecated_function( 'WC_Product::check_stock_status', '3.0' ); 
  208.  
  209. /** 
  210. * Get and return related products. 
  211. * @deprecated 3.0.0 Use wc_get_related_products instead. 
  212. */ 
  213. public function get_related( $limit = 5 ) { 
  214. wc_deprecated_function( 'WC_Product::get_related', '3.0', 'wc_get_related_products' ); 
  215. return wc_get_related_products( $this->get_id(), $limit ); 
  216.  
  217. /** 
  218. * Retrieves related product terms. 
  219. * @deprecated 3.0.0 Use wc_get_product_term_ids instead. 
  220. */ 
  221. protected function get_related_terms( $term ) { 
  222. wc_deprecated_function( 'WC_Product::get_related_terms', '3.0', 'wc_get_product_term_ids' ); 
  223. return array_merge( array( 0 ), wc_get_product_term_ids( $this->get_id(), $term ) ); 
  224.  
  225. /** 
  226. * Builds the related posts query. 
  227. * @deprecated 3.0.0 Use Product Data Store get_related_products_query instead. 
  228. */ 
  229. protected function build_related_query( $cats_array, $tags_array, $exclude_ids, $limit ) { 
  230. wc_deprecated_function( 'WC_Product::build_related_query', '3.0', 'Product Data Store get_related_products_query' ); 
  231. $data_store = WC_Data_Store::load( 'product' ); 
  232. return $data_store->get_related_products_query( $cats_array, $tags_array, $exclude_ids, $limit ); 
  233.  
  234. /** 
  235. * Returns the child product. 
  236. * @deprecated 3.0.0 Use wc_get_product instead. 
  237. * @param mixed $child_id 
  238. * @return WC_Product|WC_Product|WC_Product_variation 
  239. */ 
  240. public function get_child( $child_id ) { 
  241. wc_deprecated_function( 'WC_Product::get_child', '3.0', 'wc_get_product' ); 
  242. return wc_get_product( $child_id ); 
  243.  
  244. /** 
  245. * Functions for getting parts of a price, in html, used by get_price_html. 
  246. * 
  247. * @deprecated 3.0.0 
  248. * @return string 
  249. */ 
  250. public function get_price_html_from_text() { 
  251. wc_deprecated_function( 'WC_Product::get_price_html_from_text', '3.0', 'wc_get_price_html_from_text' ); 
  252. return wc_get_price_html_from_text(); 
  253.  
  254. /** 
  255. * Functions for getting parts of a price, in html, used by get_price_html. 
  256. * 
  257. * @deprecated 3.0.0 Use wc_format_sale_price instead. 
  258. * @param string $from String or float to wrap with 'from' text 
  259. * @param mixed $to String or float to wrap with 'to' text 
  260. * @return string 
  261. */ 
  262. public function get_price_html_from_to( $from, $to ) { 
  263. wc_deprecated_function( 'WC_Product::get_price_html_from_to', '3.0', 'wc_format_price_range' ); 
  264. return apply_filters( 'woocommerce_get_price_html_from_to', wc_format_price_range( $from, $to ), $from, $to, $this ); 
  265.  
  266. /** 
  267. * Lists a table of attributes for the product page. 
  268. * @deprecated 3.0.0 Use wc_display_product_attributes instead. 
  269. */ 
  270. public function list_attributes() { 
  271. wc_deprecated_function( 'WC_Product::list_attributes', '3.0', 'wc_display_product_attributes' ); 
  272. wc_display_product_attributes( $this ); 
  273.  
  274. /** 
  275. * Returns the price (including tax). Uses customer tax rates. Can work for a specific $qty for more accurate taxes. 
  276. * 
  277. * @deprecated 3.0.0 Use wc_get_price_including_tax instead. 
  278. * @param int $qty 
  279. * @param string $price to calculate, left blank to just use get_price() 
  280. * @return string 
  281. */ 
  282. public function get_price_including_tax( $qty = 1, $price = '' ) { 
  283. wc_deprecated_function( 'WC_Product::get_price_including_tax', '3.0', 'wc_get_price_including_tax' ); 
  284. return wc_get_price_including_tax( $this, array( 'qty' => $qty, 'price' => $price ) ); 
  285.  
  286. /** 
  287. * Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting. 
  288. * 
  289. * @deprecated 3.0.0 Use wc_get_price_to_display instead. 
  290. * @param string $price to calculate, left blank to just use get_price() 
  291. * @param integer $qty passed on to get_price_including_tax() or get_price_excluding_tax() 
  292. * @return string 
  293. */ 
  294. public function get_display_price( $price = '', $qty = 1 ) { 
  295. wc_deprecated_function( 'WC_Product::get_display_price', '3.0', 'wc_get_price_to_display' ); 
  296. return wc_get_price_to_display( $this, array( 'qty' => $qty, 'price' => $price ) ); 
  297.  
  298. /** 
  299. * Returns the price (excluding tax) - ignores tax_class filters since the price may *include* tax and thus needs subtracting. 
  300. * Uses store base tax rates. Can work for a specific $qty for more accurate taxes. 
  301. * 
  302. * @deprecated 3.0.0 Use wc_get_price_excluding_tax instead. 
  303. * @param int $qty 
  304. * @param string $price to calculate, left blank to just use get_price() 
  305. * @return string 
  306. */ 
  307. public function get_price_excluding_tax( $qty = 1, $price = '' ) { 
  308. wc_deprecated_function( 'WC_Product::get_price_excluding_tax', '3.0', 'wc_get_price_excluding_tax' ); 
  309. return wc_get_price_excluding_tax( $this, array( 'qty' => $qty, 'price' => $price ) ); 
  310.  
  311. /** 
  312. * Adjust a products price dynamically. 
  313. * 
  314. * @deprecated 3.0.0 
  315. * @param mixed $price 
  316. */ 
  317. public function adjust_price( $price ) { 
  318. wc_deprecated_function( 'WC_Product::adjust_price', '3.0', 'WC_Product::set_price / WC_Product::get_price' ); 
  319. $this->data['price'] = $this->data['price'] + $price; 
  320.  
  321. /** 
  322. * Returns the product categories. 
  323. * 
  324. * @deprecated 3.0.0 
  325. * @param string $sep (default: ', '). 
  326. * @param string $before (default: ''). 
  327. * @param string $after (default: ''). 
  328. * @return string 
  329. */ 
  330. public function get_categories( $sep = ', ', $before = '', $after = '' ) { 
  331. wc_deprecated_function( 'WC_Product::get_categories', '3.0', 'wc_get_product_category_list' ); 
  332. return wc_get_product_category_list( $this->get_id(), $sep, $before, $after ); 
  333.  
  334. /** 
  335. * Returns the product tags. 
  336. * 
  337. * @deprecated 3.0.0 
  338. * @param string $sep (default: ', '). 
  339. * @param string $before (default: ''). 
  340. * @param string $after (default: ''). 
  341. * @return array 
  342. */ 
  343. public function get_tags( $sep = ', ', $before = '', $after = '' ) { 
  344. wc_deprecated_function( 'WC_Product::get_tags', '3.0', 'wc_get_product_tag_list' ); 
  345. return wc_get_product_tag_list( $this->get_id(), $sep, $before, $after ); 
  346.  
  347. /** 
  348. * Get the product's post data. 
  349. * 
  350. * @deprecated 3.0.0 
  351. * @return WP_Post 
  352. */ 
  353. public function get_post_data() { 
  354. wc_deprecated_function( 'WC_Product::get_post_data', '3.0', 'get_post' ); 
  355.  
  356. // In order to keep backwards compatibility it's required to use the parent data for variations. 
  357. if ( $this->is_type( 'variation' ) ) { 
  358. $post_data = get_post( $this->get_parent_id() ); 
  359. } else { 
  360. $post_data = get_post( $this->get_id() ); 
  361.  
  362. return $post_data; 
  363.  
  364. /** 
  365. * Get the parent of the post. 
  366. * 
  367. * @deprecated 3.0.0 
  368. * @return int 
  369. */ 
  370. public function get_parent() { 
  371. wc_deprecated_function( 'WC_Product::get_parent', '3.0', 'WC_Product::get_parent_id' ); 
  372. return apply_filters( 'woocommerce_product_parent', absint( $this->get_post_data()->post_parent ), $this ); 
  373.  
  374. /** 
  375. * Returns the upsell product ids. 
  376. * 
  377. * @deprecated 3.0.0 
  378. * @return array 
  379. */ 
  380. public function get_upsells() { 
  381. wc_deprecated_function( 'WC_Product::get_upsells', '3.0', 'WC_Product::get_upsell_ids' ); 
  382. return apply_filters( 'woocommerce_product_upsell_ids', $this->get_upsell_ids(), $this ); 
  383.  
  384. /** 
  385. * Returns the cross sell product ids. 
  386. * 
  387. * @deprecated 3.0.0 
  388. * @return array 
  389. */ 
  390. public function get_cross_sells() { 
  391. wc_deprecated_function( 'WC_Product::get_cross_sells', '3.0', 'WC_Product::get_cross_sell_ids' ); 
  392. return apply_filters( 'woocommerce_product_crosssell_ids', $this->get_cross_sell_ids(), $this ); 
  393.  
  394. /** 
  395. * Check if variable product has default attributes set. 
  396. * 
  397. * @deprecated 3.0.0 
  398. * @return bool 
  399. */ 
  400. public function has_default_attributes() { 
  401. wc_deprecated_function( 'WC_Product_Variable::has_default_attributes', '3.0', 'a check against WC_Product::get_default_attributes directly' ); 
  402. if ( ! $this->get_default_attributes() ) { 
  403. return true; 
  404. return false; 
  405.  
  406. /** 
  407. * Get variation ID. 
  408. * 
  409. * @deprecated 3.0.0 
  410. * @return int 
  411. */ 
  412. public function get_variation_id() { 
  413. wc_deprecated_function( 'WC_Product::get_variation_id', '3.0', 'WC_Product::get_id(). It will always be the variation ID if this is a variation.' ); 
  414. return $this->get_id(); 
  415.  
  416. /** 
  417. * Get product variation description. 
  418. * 
  419. * @deprecated 3.0.0 
  420. * @return string 
  421. */ 
  422. public function get_variation_description() { 
  423. wc_deprecated_function( 'WC_Product::get_variation_description', '3.0', 'WC_Product::get_description()' ); 
  424. return $this->get_description(); 
  425.  
  426. /** 
  427. * Check if all variation's attributes are set. 
  428. * 
  429. * @deprecated 3.0.0 
  430. * @return boolean 
  431. */ 
  432. public function has_all_attributes_set() { 
  433. wc_deprecated_function( 'WC_Product::has_all_attributes_set', '3.0', 'an array filter on get_variation_attributes for a quick solution.' ); 
  434. $set = true; 
  435.  
  436. // undefined attributes have null strings as array values 
  437. foreach ( $this->get_variation_attributes() as $att ) { 
  438. if ( ! $att ) { 
  439. $set = false; 
  440. break; 
  441. return $set; 
  442.  
  443. /** 
  444. * Returns whether or not the variations parent is visible. 
  445. * 
  446. * @deprecated 3.0.0 
  447. * @return bool 
  448. */ 
  449. public function parent_is_visible() { 
  450. wc_deprecated_function( 'WC_Product::parent_is_visible', '3.0' ); 
  451. return $this->is_visible(); 
  452.  
  453. /** 
  454. * Get total stock - This is the stock of parent and children combined. 
  455. * 
  456. * @deprecated 3.0.0 
  457. * @return int 
  458. */ 
  459. public function get_total_stock() { 
  460. wc_deprecated_function( 'WC_Product::get_total_stock', '3.0', 'get_stock_quantity on each child. Beware of performance issues in doing so.' ); 
  461. if ( sizeof( $this->get_children() ) > 0 ) { 
  462. $total_stock = max( 0, $this->get_stock_quantity() ); 
  463.  
  464. foreach ( $this->get_children() as $child_id ) { 
  465. if ( 'yes' === get_post_meta( $child_id, '_manage_stock', true ) ) { 
  466. $stock = get_post_meta( $child_id, '_stock', true ); 
  467. $total_stock += max( 0, wc_stock_amount( $stock ) ); 
  468. } else { 
  469. $total_stock = $this->get_stock_quantity(); 
  470. return wc_stock_amount( $total_stock ); 
  471.  
  472. /** 
  473. * Get formatted variation data with WC < 2.4 back compat and proper formatting of text-based attribute names. 
  474. * 
  475. * @deprecated 3.0.0 
  476. * @return string 
  477. */ 
  478. public function get_formatted_variation_attributes( $flat = false ) { 
  479. wc_deprecated_function( 'WC_Product::get_formatted_variation_attributes', '3.0', 'wc_get_formatted_variation' ); 
  480. return wc_get_formatted_variation( $this, $flat ); 
  481.  
  482. /** 
  483. * Sync variable product prices with the children lowest/highest prices. 
  484. * 
  485. * @deprecated 3.0.0 not used in core. 
  486. */ 
  487. public function variable_product_sync( $product_id = '' ) { 
  488. wc_deprecated_function( 'WC_Product::variable_product_sync', '3.0' ); 
  489. if ( empty( $product_id ) ) { 
  490. $product_id = $this->get_id(); 
  491.  
  492. // Sync prices with children 
  493. if ( is_callable( array( __CLASS__, 'sync' ) ) ) { 
  494. self::sync( $product_id ); 
  495.  
  496. /** 
  497. * Sync the variable product's attributes with the variations. 
  498. */ 
  499. public static function sync_attributes( $product, $children = false ) { 
  500. if ( ! is_a( $product, 'WC_Product' ) ) { 
  501. $product = wc_get_product( $product ); 
  502.  
  503. /** 
  504. * Pre 2.4 handling where 'slugs' were saved instead of the full text attribute. 
  505. * Attempt to get full version of the text attribute from the parent and UPDATE meta. 
  506. */ 
  507. if ( version_compare( get_post_meta( $product->get_id(), '_product_version', true ), '2.4.0', '<' ) ) { 
  508. $parent_attributes = array_filter( (array) get_post_meta( $product->get_id(), '_product_attributes', true ) ); 
  509.  
  510. if ( ! $children ) { 
  511. $children = $product->get_children( 'edit' ); 
  512.  
  513. foreach ( $children as $child_id ) { 
  514. $all_meta = get_post_meta( $child_id ); 
  515.  
  516. foreach ( $all_meta as $name => $value ) { 
  517. if ( 0 !== strpos( $name, 'attribute_' ) ) { 
  518. continue; 
  519. if ( sanitize_title( $value[0] ) === $value[0] ) { 
  520. foreach ( $parent_attributes as $attribute ) { 
  521. if ( 'attribute_' . sanitize_title( $attribute['name'] ) !== $name ) { 
  522. continue; 
  523. $text_attributes = wc_get_text_attributes( $attribute['value'] ); 
  524. foreach ( $text_attributes as $text_attribute ) { 
  525. if ( sanitize_title( $text_attribute ) === $value[0] ) { 
  526. update_post_meta( $child_id, $name, $text_attribute ); 
  527. break; 
  528.  
  529. /** 
  530. * Match a variation to a given set of attributes using a WP_Query. 
  531. * @deprecated 3.0.0 in favour of Product data store's find_matching_product_variation. 
  532. */ 
  533. public function get_matching_variation( $match_attributes = array() ) { 
  534. wc_deprecated_function( 'WC_Product::get_matching_variation', '3.0', 'Product data store find_matching_product_variation' ); 
  535. $data_store = WC_Data_Store::load( 'product' ); 
  536. return $data_store->find_matching_product_variation( $this, $match_attributes ); 
  537.  
  538. /** 
  539. * Returns whether or not we are showing dimensions on the product page. 
  540. * @deprecated 3.0.0 Unused. 
  541. * @return bool 
  542. */ 
  543. public function enable_dimensions_display() { 
  544. wc_deprecated_function( 'WC_Product::enable_dimensions_display', '3.0' ); 
  545. return apply_filters( 'wc_product_enable_dimensions_display', true ) && ( $this->has_dimensions() || $this->has_weight() || $this->child_has_weight() || $this->child_has_dimensions() ); 
  546.  
  547. /** 
  548. * Returns the product rating in html format. 
  549. * 
  550. * @deprecated 3.0.0 
  551. * @param string $rating (default: '') 
  552. * @return string 
  553. */ 
  554. public function get_rating_html( $rating = null ) { 
  555. wc_deprecated_function( 'WC_Product::get_rating_html', '3.0', 'wc_get_rating_html' ); 
  556. return wc_get_rating_html( $rating ); 
  557.  
  558. /** 
  559. * Sync product rating. Can be called statically. 
  560. * 
  561. * @deprecated 3.0.0 
  562. * @param int $post_id 
  563. */ 
  564. public static function sync_average_rating( $post_id ) { 
  565. wc_deprecated_function( 'WC_Product::sync_average_rating', '3.0', 'WC_Comments::get_average_rating_for_product or leave to CRUD.' ); 
  566. $average = WC_Comments::get_average_rating_for_product( wc_get_product( $post_id ) ); 
  567. update_post_meta( $post_id, '_wc_average_rating', $average ); 
  568.  
  569. /** 
  570. * Sync product rating count. Can be called statically. 
  571. * 
  572. * @deprecated 3.0.0 
  573. * @param int $post_id 
  574. */ 
  575. public static function sync_rating_count( $post_id ) { 
  576. wc_deprecated_function( 'WC_Product::sync_rating_count', '3.0', 'WC_Comments::get_rating_counts_for_product or leave to CRUD.' ); 
  577. $counts = WC_Comments::get_rating_counts_for_product( wc_get_product( $post_id ) ); 
  578. update_post_meta( $post_id, '_wc_rating_count', $counts ); 
  579.  
  580. /** 
  581. * Same as get_downloads in CRUD. 
  582. * 
  583. * @deprecated 3.0.0 
  584. * @return array 
  585. */ 
  586. public function get_files() { 
  587. wc_deprecated_function( 'WC_Product::get_files', '3.0', 'WC_Product::get_downloads' ); 
  588. return $this->get_downloads(); 
  589.  
  590. /** 
  591. * @deprected 3.0.0 Sync is taken care of during save - no need to call this directly. 
  592. */ 
  593. public function grouped_product_sync() { 
  594. wc_deprecated_function( 'WC_Product::grouped_product_sync', '3.0' ); 
.