Automattic\WooCommerce\Blocks\BlockTypes
RelatedProducts::get_related_products_ids()
Get related products ids. The logic is copied from the core function woocommerce_related_products. https://github.com/woocommerce/woocommerce/blob/ca49caabcba84ce9f60a03c6d3534ec14b350b80/plugins/woocommerce/includes/wc-template-functions.php/#L2039-L2074
Метод класса: RelatedProducts{}
Хуков нет.
Возвращает
Массив
. Products ids.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_related_products_ids( $product_per_page );
- $product_per_page(number)
- Products per page.
По умолчанию: 5
Код RelatedProducts::get_related_products_ids() RelatedProducts::get related products ids WC 9.2.3
private function get_related_products_ids( $product_per_page = 5 ) { global $post; $product = wc_get_product( $post->ID ); $related_products = array_filter( array_map( 'wc_get_product', wc_get_related_products( $product->get_id(), $product_per_page, $product->get_upsell_ids() ) ), 'wc_products_array_filter_visible' ); $related_products = wc_products_array_orderby( $related_products, 'rand', 'desc' ); $related_product_ids = array_map( function( $product ) { return $product->get_id(); }, $related_products ); return $related_product_ids; }