WC_Product_Variable_Data_Store_CPT::read_children()
Loads variation child IDs.
Метод класса: WC_Product_Variable_Data_Store_CPT{}
Хуки из метода
Возвращает
Массив
.
Использование
$WC_Product_Variable_Data_Store_CPT = new WC_Product_Variable_Data_Store_CPT(); $WC_Product_Variable_Data_Store_CPT->read_children( $product, $force_read );
- $product(WC_Product) (обязательный) (передается по ссылке — &)
- Product object.
- $force_read(true|false)
- True to bypass the transient.
По умолчанию: false
Код WC_Product_Variable_Data_Store_CPT::read_children() WC Product Variable Data Store CPT::read children WC 9.8.1
public function read_children( &$product, $force_read = false ) { $children_transient_name = 'wc_product_children_' . $product->get_id(); $children = get_transient( $children_transient_name ); if ( empty( $children ) || ! is_array( $children ) ) { $children = array(); } $transient_version = WC_Cache_Helper::get_transient_version( 'product' ); if ( ! $force_read && $children ) { // Validate the children data. if ( ! $this->validate_children_data( $children, $transient_version ) ) { $children = array(); $force_read = true; } } if ( ! isset( $children['all'] ) || ! isset( $children['visible'] ) || $force_read ) { $all_args = array( 'post_parent' => $product->get_id(), 'post_type' => 'product_variation', 'orderby' => array( 'menu_order' => 'ASC', 'ID' => 'ASC', ), 'fields' => 'ids', 'post_status' => array( ProductStatus::PUBLISH, ProductStatus::PRIVATE ), 'numberposts' => -1, // phpcs:ignore WordPress.VIP.PostsPerPage.posts_per_page_numberposts ); $visible_only_args = $all_args; $visible_only_args['post_status'] = ProductStatus::PUBLISH; if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) { $visible_only_args['tax_query'][] = array( 'taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => ProductStockStatus::OUT_OF_STOCK, 'operator' => 'NOT IN', ); } $children['all'] = get_posts( apply_filters( 'woocommerce_variable_children_args', $all_args, $product, false ) ); $children['visible'] = get_posts( apply_filters( 'woocommerce_variable_children_args', $visible_only_args, $product, true ) ); $children['version'] = $transient_version; // Validate the children data before storing it in the transient. if ( $this->validate_children_data( $children, $transient_version ) ) { set_transient( $children_transient_name, $children, DAY_IN_SECONDS * 30 ); } } $children['all'] = wp_parse_id_list( (array) $children['all'] ); $children['visible'] = wp_parse_id_list( (array) $children['visible'] ); return $children; }