Automattic\WooCommerce\StoreApi\Schemas\V1

ProductSchema::get_item_response()publicWC 1.0

Convert a WooCommerce product into an object suitable for the response.

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

Хуков нет.

Возвращает

Массив.

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

$ProductSchema = new ProductSchema();
$ProductSchema->get_item_response( $product );
$product(\WC_Product) (обязательный)
Product instance.

Код ProductSchema::get_item_response() WC 8.7.0

public function get_item_response( $product ) {
	return [
		'id'                  => $product->get_id(),
		'name'                => $this->prepare_html_response( $product->get_title() ),
		'slug'                => $product->get_slug(),
		'parent'              => $product->get_parent_id(),
		'type'                => $product->get_type(),
		'variation'           => $this->prepare_html_response( $product->is_type( 'variation' ) ? wc_get_formatted_variation( $product, true, true, false ) : '' ),
		'permalink'           => $product->get_permalink(),
		'sku'                 => $this->prepare_html_response( $product->get_sku() ),
		'short_description'   => $this->prepare_html_response( wc_format_content( wp_kses_post( $product->get_short_description() ) ) ),
		'description'         => $this->prepare_html_response( wc_format_content( wp_kses_post( $product->get_description() ) ) ),
		'on_sale'             => $product->is_on_sale(),
		'prices'              => (object) $this->prepare_product_price_response( $product ),
		'price_html'          => $this->prepare_html_response( $product->get_price_html() ),
		'average_rating'      => (string) $product->get_average_rating(),
		'review_count'        => $product->get_review_count(),
		'images'              => $this->get_images( $product ),
		'categories'          => $this->get_term_list( $product, 'product_cat' ),
		'tags'                => $this->get_term_list( $product, 'product_tag' ),
		'attributes'          => $this->get_attributes( $product ),
		'variations'          => $this->get_variations( $product ),
		'has_options'         => $product->has_options(),
		'is_purchasable'      => $product->is_purchasable(),
		'is_in_stock'         => $product->is_in_stock(),
		'is_on_backorder'     => 'onbackorder' === $product->get_stock_status(),
		'low_stock_remaining' => $this->get_low_stock_remaining( $product ),
		'sold_individually'   => $product->is_sold_individually(),
		'add_to_cart'         => (object) array_merge(
			[
				'text'        => $this->prepare_html_response( $product->add_to_cart_text() ),
				'description' => $this->prepare_html_response( $product->add_to_cart_description() ),
				'url'         => $this->prepare_html_response( $product->add_to_cart_url() ),
			],
			( new QuantityLimits() )->get_add_to_cart_limits( $product )
		),
		self::EXTENDING_KEY   => $this->get_extended_data( self::IDENTIFIER, $product ),

	];
}