Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLTypes\Interfaces

Product{}WC 1.0

No Hooks.

Usage

$Product = new Product();
// use class methods

Methods

  1. public static get()

Product{} code WC 10.9.4

class Product {
	private static ?InterfaceType $instance = null;

	public static function get(): InterfaceType {
		if ( null === self::$instance ) {
			self::$instance = new InterfaceType(
				array(
					'name'        => 'Product',
					'description' => __( 'A WooCommerce product.', 'woocommerce' ),
					'fields'      => fn() => array(
						'name'              => array(
							'type'        => Type::nonNull( Type::string() ),
							'description' => __( 'The product name.', 'woocommerce' ),
						),
						'slug'              => array(
							'type'        => Type::nonNull( Type::string() ),
							'description' => __( 'The product slug.', 'woocommerce' ),
						),
						'sku'               => array(
							'type'        => Type::string(),
							'description' => __( 'The product SKU.', 'woocommerce' ),
						),
						'description'       => array(
							'type'        => Type::nonNull( Type::string() ),
							'description' => __( 'The full product description.', 'woocommerce' ),
						),
						'short_description' => array(
							'type'              => Type::nonNull( Type::string() ),
							'description'       => __( 'The short product description.', 'woocommerce' ),
							'deprecationReason' => 'Use description instead.',
						),
						'status'            => array(
							'type'        => Type::nonNull( ProductStatusType::get() ),
							'description' => __( 'The product status.', 'woocommerce' ),
						),
						'raw_status'        => array(
							'type'        => Type::nonNull( Type::string() ),
							'description' => __( 'The raw status as stored in WordPress. Useful when status is OTHER (e.g. plugin-added post statuses).', 'woocommerce' ),
						),
						'product_type'      => array(
							'type'        => Type::nonNull( ProductTypeType::get() ),
							'description' => __( 'The product type.', 'woocommerce' ),
						),
						'raw_product_type'  => array(
							'type'        => Type::nonNull( Type::string() ),
							'description' => __( 'The raw product type as stored in WooCommerce. Useful when product_type is OTHER (e.g. plugin-added types like subscription, bundle).', 'woocommerce' ),
						),
						'regular_price'     => array(
							'type'        => Type::string(),
							'description' => __( 'The regular price of the product. Null when not set.', 'woocommerce' ),
							'args'        => array(
								'formatted' => array(
									'type'         => Type::boolean(),
									'defaultValue' => true,
									'description'  => __( 'Whether to apply currency formatting.', 'woocommerce' ),
								),
							),
						),
						'sale_price'        => array(
							'type'        => Type::string(),
							'description' => __( 'The sale price of the product.', 'woocommerce' ),
							'args'        => array(
								'formatted' => array(
									'type'         => Type::boolean(),
									'defaultValue' => true,
									'description'  => __( 'When true, returns price with currency symbol.', 'woocommerce' ),
								),
							),
						),
						'stock_status'      => array(
							'type'        => Type::nonNull( StockStatusType::get() ),
							'description' => __( 'The stock status of the product.', 'woocommerce' ),
						),
						'raw_stock_status'  => array(
							'type'        => Type::nonNull( Type::string() ),
							'description' => __( 'The raw stock status as stored in WooCommerce. Useful when stock_status is OTHER (e.g. plugin-added statuses).', 'woocommerce' ),
						),
						'stock_quantity'    => array(
							'type'        => Type::int(),
							'description' => __( 'The number of items in stock.', 'woocommerce' ),
						),
						'dimensions'        => array(
							'type'        => ProductDimensions::get(),
							'description' => __( 'The product dimensions.', 'woocommerce' ),
						),
						'images'            => array(
							'type'        => Type::nonNull( Type::listOf( Type::nonNull( ProductImage::get() ) ) ),
							'description' => __( 'The product images.', 'woocommerce' ),
						),
						'attributes'        => array(
							'type'        => Type::nonNull( Type::listOf( Type::nonNull( ProductAttribute::get() ) ) ),
							'description' => __( 'The product attributes.', 'woocommerce' ),
						),
						'reviews'           => array(
							'type'        => Type::nonNull( ProductReviewConnectionType::get() ),
							'description' => __( 'Customer reviews for this product.', 'woocommerce' ),
						),
						'date_created'      => array(
							'type'        => DateTimeType::get(),
							'description' => __( 'The date the product was created.', 'woocommerce' ),
						),
						'date_modified'     => array(
							'type'        => DateTimeType::get(),
							'description' => __( 'The date the product was last modified.', 'woocommerce' ),
						),
						'id'                => array(
							'type'        => Type::nonNull( Type::int() ),
							'description' => __( 'The unique numeric identifier.', 'woocommerce' ),
						),
					),
					'resolveType' => function ( $value ) {
						$class = get_class( $value );
						$map = array(
							'Automattic\WooCommerce\Api\Types\Products\ProductVariation' => ProductVariationType::get(),
							'Automattic\WooCommerce\Api\Types\Products\ExternalProduct' => ExternalProductType::get(),
							'Automattic\WooCommerce\Api\Types\Products\VariableProduct' => VariableProductType::get(),
							'Automattic\WooCommerce\Api\Types\Products\SimpleProduct' => SimpleProductType::get(),
						);
						return $map[ $class ] ?? null;
					},
				)
			);
		}
		return self::$instance;
	}
}