WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Получай пассивный доход от сайта с помощью браузерных PUSH уведомлений
функция не описана

WC_Product_Data_Store_CPT::get_related_products_query() public WC 3.0.0

Builds the related posts query.

{} Это метод класса: WC_Product_Data_Store_CPT{}

Хуков нет.

Возвращает

Массив. Ничего.

Использование

$WC_Product_Data_Store_CPT = new WC_Product_Data_Store_CPT();
$WC_Product_Data_Store_CPT->get_related_products_query( $cats_array, $tags_array, $exclude_ids, $limit );
$cats_array(массив) (обязательный)
List of categories IDs.
$tags_array(массив) (обязательный)
List of tags IDs.
$exclude_ids(массив) (обязательный)
Excluded IDs.
$limit(число) (обязательный)
Limit of results.

Список изменений

С версии 3.0.0 Введена.

Код WC_Product_Data_Store_CPT::get_related_products_query() WC 5.3.0

<?php
public function get_related_products_query( $cats_array, $tags_array, $exclude_ids, $limit ) {
	global $wpdb;

	$include_term_ids            = array_merge( $cats_array, $tags_array );
	$exclude_term_ids            = array();
	$product_visibility_term_ids = wc_get_product_visibility_term_ids();

	if ( $product_visibility_term_ids['exclude-from-catalog'] ) {
		$exclude_term_ids[] = $product_visibility_term_ids['exclude-from-catalog'];
	}

	if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) && $product_visibility_term_ids['outofstock'] ) {
		$exclude_term_ids[] = $product_visibility_term_ids['outofstock'];
	}

	$query = array(
		'fields' => "
			SELECT DISTINCT ID FROM {$wpdb->posts} p
		",
		'join'   => '',
		'where'  => "
			WHERE 1=1
			AND p.post_status = 'publish'
			AND p.post_type = 'product'

		",
		'limits' => '
			LIMIT ' . absint( $limit ) . '
		',
	);

	if ( count( $exclude_term_ids ) ) {
		$query['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 = p.ID';
		$query['where'] .= ' AND exclude_join.object_id IS NULL';
	}

	if ( count( $include_term_ids ) ) {
		$query['join'] .= " INNER JOIN ( SELECT object_id FROM {$wpdb->term_relationships} INNER JOIN {$wpdb->term_taxonomy} using( term_taxonomy_id ) WHERE term_id IN ( " . implode( ',', array_map( 'absint', $include_term_ids ) ) . ' ) ) AS include_join ON include_join.object_id = p.ID';
	}

	if ( count( $exclude_ids ) ) {
		$query['where'] .= ' AND p.ID NOT IN ( ' . implode( ',', array_map( 'absint', $exclude_ids ) ) . ' )';
	}

	return $query;
}