WC_Product_Data_Store_CPT::get_on_sale_products()
Returns an array of on sale products, as an array of objects with an ID and parent_id present. Example: $return[0]->id, $return[0]->parent_id.
Метод класса: WC_Product_Data_Store_CPT{}
Хуков нет.
Возвращает
Массив
.
Использование
$WC_Product_Data_Store_CPT = new WC_Product_Data_Store_CPT(); $WC_Product_Data_Store_CPT->get_on_sale_products();
Список изменений
С версии 3.0.0 | Введена. |
Код WC_Product_Data_Store_CPT::get_on_sale_products() WC Product Data Store CPT::get on sale products WC 9.8.1
public function get_on_sale_products() { global $wpdb; $exclude_term_ids = array(); $outofstock_join = ''; $outofstock_where = ''; $non_published_where = ''; $product_visibility_term_ids = wc_get_product_visibility_term_ids(); if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) && $product_visibility_term_ids[ ProductStockStatus::OUT_OF_STOCK ] ) { $exclude_term_ids[] = $product_visibility_term_ids[ ProductStockStatus::OUT_OF_STOCK ]; } if ( count( $exclude_term_ids ) ) { $outofstock_join = " LEFT JOIN ( SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN ( " . implode( ',', array_map( 'absint', $exclude_term_ids ) ) . ' ) ) AS exclude_join ON exclude_join.object_id = id'; $outofstock_where = ' AND exclude_join.object_id IS NULL'; } // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared return $wpdb->get_results( " SELECT posts.ID as id, posts.post_parent as parent_id FROM {$wpdb->posts} AS posts INNER JOIN {$wpdb->wc_product_meta_lookup} AS lookup ON posts.ID = lookup.product_id $outofstock_join WHERE posts.post_type IN ( 'product', 'product_variation' ) AND posts.post_status = 'publish' AND lookup.onsale = 1 $outofstock_where AND posts.post_parent NOT IN ( SELECT ID FROM `$wpdb->posts` as posts WHERE posts.post_type = 'product' AND posts.post_parent = 0 AND posts.post_status != 'publish' ) GROUP BY posts.ID " ); // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared }