WooProductVariation class

WooCommerce Product Variation Model

Represents a product variation in WooCommerce, which is a specific version of a variable product with its own attributes, pricing, inventory, and other properties. Variations allow customers to choose different options like size, color, material, etc., for the same base product.

Key Features

  • Attribute Management: Store and manage variation-specific attributes
  • Pricing Control: Set individual prices, sale prices, and sale periods
  • Inventory Management: Track stock levels, backorders, and stock status
  • Download Support: Handle downloadable products with download limits and expiry
  • Shipping Configuration: Set weight, dimensions, and shipping class
  • Tax Configuration: Configure tax status and tax class per variation

Usage Examples

Creating a Product Variation

final variation = WooProductVariation(
  sku: 'T-SHIRT-RED-L',
  price: 25.99,
  regularPrice: 29.99,
  salePrice: 25.99,
  stockQuantity: 50,
  stockStatus: WooProductStockStatus.instock,
);

Working with Variation Data

// Check if variation is on sale
if (variation.onSale == true) {
  print('Sale price: ${variation.salePrice}');
}

// Check stock availability
if (variation.stockStatus == WooProductStockStatus.instock) {
  print('Available quantity: ${variation.stockQuantity}');
}

JSON Serialization

The class supports full JSON serialization for API communication:

// Convert to JSON for API requests
final json = variation.toJson();

// Create from JSON response
final variation = WooProductVariation.fromJson(jsonData);

Constructors

WooProductVariation({int? id, DateTime? dateCreated, DateTime? dateCreatedGmt, DateTime? dateModified, DateTime? dateModifiedGmt, String? description, String? permalink, String? sku, double? price, List<WooProductItemAttribute> attributes = const [], double? regularPrice, double? salePrice, DateTime? dateOnSaleFrom, DateTime? dateOnSaleFromGmt, DateTime? dateOnSaleTo, DateTime? dateOnSaleToGmt, bool? onSale, WooProductStatus? status, bool? purchasable, bool? virtual, bool? downloadable, List<WooProductDownload> downloads = const [], int? downloadLimit, int? downloadExpiry, WooProductTaxStatus? taxStatus, String? taxClass, bool? manageStock, int? stockQuantity, WooProductStockStatus? stockStatus, WooProductBackorder? backorders, bool? backordersAllowed, bool? backordered, String? weight, String? shippingClass, int? shippingClassId, int? menuOrder, WooProductDimension dimensions = const WooProductDimension(), List<WooMetaData> metaData = const [], WooProductImage? image})
Creates a new WooProductVariation instance
WooProductVariation.fake()
Creates a fake WooProductVariation instance for testing purposes
factory
WooProductVariation.fromJson(Map<String, dynamic> json)
Creates a WooProductVariation instance from JSON data

Properties

attributes List<WooProductItemAttribute>
List of attributes.
getter/setter pair
backordered bool?
Shows if the variation is on backordered.
getter/setter pair
backorders WooProductBackorder?
If managing stock, this controls if backorders are allowed. Options: no, notify and yes. Default is no.
getter/setter pair
backordersAllowed bool?
Shows if backorders are allowed.
getter/setter pair
dateCreated DateTime?
The date the variation was created, in the site's timezone.
getter/setter pair
dateCreatedGmt DateTime?
The date the variation was created, as GMT.
getter/setter pair
dateModified DateTime?
The date the variation was last modified, in the site's timezone.
getter/setter pair
dateModifiedGmt DateTime?
The date the variation was last modified, as GMT.
getter/setter pair
dateOnSaleFrom DateTime?
Start date of sale price, in the site's timezone.
getter/setter pair
dateOnSaleFromGmt DateTime?
Start date of sale price, as GMT.
getter/setter pair
dateOnSaleTo DateTime?
End date of sale price, in the site's timezone.
getter/setter pair
dateOnSaleToGmt DateTime?
End date of sale price, as GMT.
getter/setter pair
description String?
Variation description.
getter/setter pair
dimensions WooProductDimension
Variation dimensions.
getter/setter pair
downloadable bool?
If the variation is downloadable. Default is false.
getter/setter pair
downloadExpiry int?
Number of days until access to downloadable files expires. Default is -1.
getter/setter pair
downloadLimit int?
Number of times downloadable files can be downloaded after purchase. Default is -1.
getter/setter pair
downloads List<WooProductDownload>
If the variation is downloadable. Default is false.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
id int?
Unique identifier for the resource.
getter/setter pair
image WooProductImage?
Variation image data.
getter/setter pair
manageStock bool?
Stock management at variation level. Default is false.
getter/setter pair
Menu order, used to custom sort products.
getter/setter pair
metaData List<WooMetaData>
Meta data.
getter/setter pair
onSale bool?
Shows if the variation is on sale.
getter/setter pair
Variation URL.
getter/setter pair
price double?
Current variation price.
getter/setter pair
purchasable bool?
Shows if the variation can be bought.
getter/setter pair
regularPrice double?
Variation regular price.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
salePrice double?
Variation sale price.
getter/setter pair
shippingClass String?
Shipping class slug.
getter/setter pair
shippingClassId int?
Shipping class ID.
getter/setter pair
sku String?
Unique identifier.
getter/setter pair
status WooProductStatus?
Variation status. Options: draft, pending, private and publish. Default is publish.
getter/setter pair
stockQuantity int?
Stock quantity.
getter/setter pair
stockStatus WooProductStockStatus?
Controls the stock status of the product. Options: instock, outofstock, onbackorder. Default is instock.
getter/setter pair
taxClass String?
Tax class.
getter/setter pair
taxStatus WooProductTaxStatus?
Tax status. Options: taxable, shipping and none. Default is taxable.
getter/setter pair
virtual bool?
If the variation is virtual. Default is false.
getter/setter pair
weight String?
Variation weight.
getter/setter pair

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, dynamic>
Converts the WooProductVariation instance to JSON format
toString() String
Returns a string representation of the WooProductVariation instance
override

Operators

operator ==(Object other) bool
The equality operator.
inherited