Automattic\WooCommerce\StoreApi\Routes\V1

ProductReviews::get_unlocked_password_protected_product_ids │ private │ WC 1.0

Password-protected product IDs the visitor has unlocked.

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

Хуков нет.

Возвращает

int[].

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

// private - только в коде основоного (родительского) класса
$result = $this->get_unlocked_password_protected_product_ids( $candidate_product_ids );
$candidate_product_ids(int[])
Product IDs already limiting the review query, if any.
По умолчанию: array()

Код ProductReviews::get_unlocked_password_protected_product_ids() WC 11.3.0

private function get_unlocked_password_protected_product_ids( $candidate_product_ids = array() ) {
	// Return early if the visitor has not submitted the password form and there is no filter in `post_password_required`.
	if ( ( ! defined( 'COOKIEHASH' ) || ! isset( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ) ) && ! has_filter( 'post_password_required' ) ) {
		return array();
	}

	$query_args = array(
		'post_type'              => 'product',
		'post_status'            => ProductStatus::PUBLISH,
		'has_password'           => true,
		'comment_count'          => array(
			'value'   => 0,
			'compare' => '!=',
		),
		'posts_per_page'         => -1,
		'orderby'                => 'none',
		'no_found_rows'          => true,
		'update_post_meta_cache' => false,
		'update_post_term_cache' => false,
	);

	if ( ! empty( $candidate_product_ids ) ) {
		$query_args['post__in'] = $candidate_product_ids;
	}

	$unlocked_ids = array();
	foreach ( get_posts( $query_args ) as $product ) {
		if ( $product instanceof \WP_Post && ! post_password_required( $product ) ) {
			$unlocked_ids[] = (int) $product->ID;
		}
	}

	return $unlocked_ids;
}