woocommerce/includes/class-wc-product-query.php

75 lines
2.2 KiB
PHP
Raw Normal View History

2017-07-12 14:44:53 +00:00
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class for parameter-based Product querying.
2017-07-28 18:59:44 +00:00
* Args and usage: https://github.com/woocommerce/woocommerce/wiki/wc_get_products-and-WC_Product_Query
2017-07-12 14:44:53 +00:00
*
* @version 3.2.0
* @since 3.2.0
* @package WooCommerce/Classes
* @category Class
*/
class WC_Product_Query extends WC_Object_Query {
2017-07-12 20:58:39 +00:00
2017-07-12 14:44:53 +00:00
/**
* Valid query vars for products.
* @return array
*/
protected function get_default_query_vars() {
return array_merge(
parent::get_default_query_vars(),
array(
2017-07-14 16:50:20 +00:00
'status' => array( 'draft', 'pending', 'private', 'publish' ),
'type' => array_merge( array_keys( wc_get_product_types() ) ),
'limit' => get_option( 'posts_per_page' ),
'include' => array(),
2017-07-12 20:58:39 +00:00
'date_created' => '',
'date_modified' => '',
'featured' => '',
2017-07-24 22:05:23 +00:00
'visibility' => '',
2017-07-12 20:58:39 +00:00
'sku' => '',
'price' => '',
'regular_price' => '',
'sale_price' => '',
'date_on_sale_from' => '',
'date_on_sale_to' => '',
'total_sales' => '',
'tax_status' => '',
'tax_class' => '',
'manage_stock' => '',
'stock_quantity' => '',
'stock_status' => '',
'backorders' => '',
'sold_individually' => '',
'weight' => '',
'length' => '',
'width' => '',
'height' => '',
'reviews_allowed' => '',
'virtual' => '',
'downloadable' => '',
2017-07-14 16:50:20 +00:00
'category' => array(),
'tag' => array(),
'shipping_class' => array(),
2017-07-12 20:58:39 +00:00
'download_limit' => '',
'download_expiry' => '',
'average_rating' => '',
'review_count' => '',
2017-07-12 14:44:53 +00:00
)
);
}
/**
* Get products matching the current query vars.
2017-08-29 15:36:50 +00:00
* @return array|object of WC_Product objects
2017-07-12 14:44:53 +00:00
*/
public function get_products() {
2017-08-18 17:25:21 +00:00
$args = apply_filters( 'woocommerce_product_object_query_args', $this->get_query_vars() );
2017-07-12 20:58:39 +00:00
$results = WC_Data_Store::load( 'product' )->query( $args );
2017-08-18 17:25:21 +00:00
return apply_filters( 'woocommerce_product_object_query', $results, $args );
2017-07-12 14:44:53 +00:00
}
}