class-wc-product-query.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Class for parameter-based Product querying
  4. *
  5. * Args and usage: https://github.com/woocommerce/woocommerce/wiki/wc_get_products-and-WC_Product_Query
  6. *
  7. * @package WooCommerce/Classes
  8. * @version 3.2.0
  9. * @since 3.2.0
  10. */
  11. defined( 'ABSPATH' ) || exit;
  12. /**
  13. * Product query class.
  14. */
  15. class WC_Product_Query extends WC_Object_Query {
  16. /**
  17. * Valid query vars for products.
  18. *
  19. * @return array
  20. */
  21. protected function get_default_query_vars() {
  22. return array_merge(
  23. parent::get_default_query_vars(),
  24. array(
  25. 'status' => array( 'draft', 'pending', 'private', 'publish' ),
  26. 'type' => array_merge( array_keys( wc_get_product_types() ) ),
  27. 'limit' => get_option( 'posts_per_page' ),
  28. 'include' => array(),
  29. 'date_created' => '',
  30. 'date_modified' => '',
  31. 'featured' => '',
  32. 'visibility' => '',
  33. 'sku' => '',
  34. 'price' => '',
  35. 'regular_price' => '',
  36. 'sale_price' => '',
  37. 'date_on_sale_from' => '',
  38. 'date_on_sale_to' => '',
  39. 'total_sales' => '',
  40. 'tax_status' => '',
  41. 'tax_class' => '',
  42. 'manage_stock' => '',
  43. 'stock_quantity' => '',
  44. 'stock_status' => '',
  45. 'backorders' => '',
  46. 'sold_individually' => '',
  47. 'weight' => '',
  48. 'length' => '',
  49. 'width' => '',
  50. 'height' => '',
  51. 'reviews_allowed' => '',
  52. 'virtual' => '',
  53. 'downloadable' => '',
  54. 'category' => array(),
  55. 'tag' => array(),
  56. 'shipping_class' => array(),
  57. 'download_limit' => '',
  58. 'download_expiry' => '',
  59. 'average_rating' => '',
  60. 'review_count' => '',
  61. )
  62. );
  63. }
  64. /**
  65. * Get products matching the current query vars.
  66. *
  67. * @return array|object of WC_Product objects
  68. */
  69. public function get_products() {
  70. $args = apply_filters( 'woocommerce_product_object_query_args', $this->get_query_vars() );
  71. $results = WC_Data_Store::load( 'product' )->query( $args );
  72. return apply_filters( 'woocommerce_product_object_query', $results, $args );
  73. }
  74. }