wc_get_products() WC 3.0.0
Standard way of retrieving products based on certain parameters.
This function should be used for product retrieval so that we have a data agnostic way to get a list of products.
Args and usage: https://github.com/woocommerce/woocommerce/wiki/wc_get_products-and-WC_Product_Query
Хуков нет.
Возвращает
Массив/stdClass. Number of pages and an array of product objects if paginate is true, or just an array of values.
Использование
wc_get_products( $args );
- $args(массив) (обязательный)
- Array of args (above).
Список изменений
С версии 3.0.0 | Введена. |
Код wc_get_products() wc get products WC 5.0.0
function wc_get_products( $args ) {
// Handle some BW compatibility arg names where wp_query args differ in naming.
$map_legacy = array(
'numberposts' => 'limit',
'post_status' => 'status',
'post_parent' => 'parent',
'posts_per_page' => 'limit',
'paged' => 'page',
);
foreach ( $map_legacy as $from => $to ) {
if ( isset( $args[ $from ] ) ) {
$args[ $to ] = $args[ $from ];
}
}
$query = new WC_Product_Query( $args );
return $query->get_products();
}