abstract-wc-legacy-product.php 21 KB

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