Automattic\WooCommerce\StoreApi\Routes\V1

ProductReviews::exclude_password_protected_product_reviews │ private │ WC 1.0

Restrict the comment query to products the visitor can access.

WP_Comment_Query already joins posts because of post_status. Filter on that join instead of building a post__not_in list of every protected product.

Метод класса: ProductReviews{}

Хуков нет.

Возвращает

array|mixed.

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

// private - только в коде основоного (родительского) класса
$result = $this->exclude_password_protected_product_reviews( $clauses, $unlocked_product_ids );
$clauses(массив|разное) (обязательный)
Comment query clauses from comments_clauses.
$unlocked_product_ids(int[]) (обязательный)
Password-protected product IDs the visitor has unlocked.

Код ProductReviews::exclude_password_protected_product_reviews() WC 11.3.0

private function exclude_password_protected_product_reviews( $clauses, $unlocked_product_ids ) {
	global $wpdb;

	if ( ! is_array( $clauses ) ) {
		return $clauses;
	}

	$where = " {$wpdb->posts}.post_password = '' ";
	if ( ! empty( $unlocked_product_ids ) ) {
		$ids   = implode( ',', array_map( 'absint', $unlocked_product_ids ) );
		$where = " ( {$wpdb->posts}.post_password = '' OR {$wpdb->posts}.ID IN ({$ids}) ) ";
	}

	$clauses['where']  = is_string( $clauses['where'] ?? null ) ? $clauses['where'] : '';
	$clauses['where'] .= ( trim( $clauses['where'] ) ? ' AND ' : '' ) . $where;

	return $clauses;
}