WordPress at Your Fingertips
function is not described

WC_Product_Data_Store_CPT::get_related_products() public WC 3.0.0

Return a list of related products (using data like categories and IDs).

{} It's a method of the class: WC_Product_Data_Store_CPT{}

Return

Array.

Usage

$WC_Product_Data_Store_CPT = new WC_Product_Data_Store_CPT();
$WC_Product_Data_Store_CPT->get_related_products( $cats_array, $tags_array, $exclude_ids, $limit, $product_id );
$cats_array(array) (required)
List of categories IDs.
$tags_array(array) (required)
List of tags IDs.
$exclude_ids(array) (required)
Excluded IDs.
$limit(int) (required)
Limit of results.
$product_id(int) (required)
Product ID.

Changelog

Since 3.0.0 Introduced.

Code of WC_Product_Data_Store_CPT::get_related_products() WC 5.6.0

public function get_related_products( $cats_array, $tags_array, $exclude_ids, $limit, $product_id ) {
	global $wpdb;

	$args = array(
		'categories'  => $cats_array,
		'tags'        => $tags_array,
		'exclude_ids' => $exclude_ids,
		'limit'       => $limit + 10,
	);

	$related_product_query = (array) apply_filters( 'woocommerce_product_related_posts_query', $this->get_related_products_query( $cats_array, $tags_array, $exclude_ids, $limit + 10 ), $product_id, $args );

	// phpcs:ignore WordPress.VIP.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared
	return $wpdb->get_col( implode( ' ', $related_product_query ) );
}