WC_API_Products::get_product()publicWC 2.1

Get the product for the given ID

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

Хуки из метода

Возвращает

Массив|WP_Error.

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

$WC_API_Products = new WC_API_Products();
$WC_API_Products->get_product( $id, $fields );
$id(int) (обязательный)
the product ID
$fields(строка)
-
По умолчанию: null

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

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

Код WC_API_Products::get_product() WC 7.5.1

public function get_product( $id, $fields = null ) {

	$id = $this->validate_request( $id, 'product', 'read' );

	if ( is_wp_error( $id ) ) {
		return $id;
	}

	$product = wc_get_product( $id );

	// add data that applies to every product type
	$product_data = $this->get_product_data( $product );

	// add variations to variable products
	if ( $product->is_type( 'variable' ) && $product->has_child() ) {
		$product_data['variations'] = $this->get_variation_data( $product );
	}

	// add the parent product data to an individual variation
	if ( $product->is_type( 'variation' ) ) {
		$product_data['parent'] = $this->get_product_data( $product->get_parent_id() );
	}

	return array( 'product' => apply_filters( 'woocommerce_api_product_response', $product_data, $product, $fields, $this->server ) );
}