WooOrder class

WooCommerce Order Model

Represents a complete WooCommerce order with all its details, line items, customer information, and financial data. This is the core model for managing orders in your WooCommerce store, supporting all order types and statuses.

Order Structure

A WooCommerce order consists of several key components:

  • Order Information: ID, number, key, status, and currency
  • Customer Data: Customer ID, IP address, and user agent
  • Addresses: Billing and shipping address information
  • Financial Data: Totals, taxes, discounts, and payment information
  • Line Items: Products, quantities, and prices in the order
  • Timestamps: Creation, modification, payment, and completion dates
  • Metadata: Custom order metadata and administrative notes

Order Lifecycle

Orders progress through different statuses during their lifecycle:

  1. Pending: Order is created but payment is pending
  2. Processing: Payment is confirmed, order is being prepared
  3. On Hold: Order is temporarily paused (e.g., awaiting payment)
  4. Completed: Order is fulfilled and delivered
  5. Cancelled: Order is cancelled before completion
  6. Refunded: Order is refunded to the customer

Key Features

  • Order Information: ID, number, key, status, currency
  • Customer Data: Customer ID, IP address, user agent
  • Addresses: Billing and shipping address information
  • Financial: Totals, taxes, discounts, payment information
  • Line Items: Products, quantities, prices in the order
  • Timestamps: Creation, modification, payment, completion dates
  • Metadata: Custom order metadata and notes

Usage Examples

Creating a New Order

final order = WooOrder(
  id: 0, // Will be assigned by WooCommerce
  status: WooOrderStatus.pending,
  currency: WooOrderCurrency.usd,
  customerId: 123,
  billing: WooBilling(
    firstName: 'John',
    lastName: 'Doe',
    email: 'john@example.com',
  ),
);

Working with Order Data

// Check order status
if (order.status == WooOrderStatus.completed) {
  print('Order is completed');
}

// Get order total
print('Order total: \$${order.total}');

// Access line items
for (final item in order.lineItems ?? []) {
  print('Item: ${item.name}, Qty: ${item.quantity}');
}

// Access billing information
if (order.billing != null) {
  print('Customer: ${order.billing!.firstName} ${order.billing!.lastName}');
  print('Email: ${order.billing!.email}');
}

Order Status Management

// Update order status
order.status = WooOrderStatus.processing;
await wooCommerce.updateOrder(order);

// Check if order is paid
if (order.datePaid != null) {
  print('Order was paid on: ${order.datePaid}');
}

// Check if order is completed
if (order.dateCompleted != null) {
  print('Order was completed on: ${order.dateCompleted}');
}

JSON Serialization

The class supports full JSON serialization for API communication:

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

// Create from JSON response
final order = WooOrder.fromJson(jsonData);

Constructors

WooOrder({required int id, int? parentId, String? number, String? orderKey, String? createdVia, String? version, WooOrderStatus? status, WooOrderCurrency? currency, DateTime? dateCreated, DateTime? dateCreatedGmt, DateTime? dateModified, DateTime? dateModifiedGmt, double? discountTotal, double? discountTax, double? shippingTotal, double? shippingTax, double? cartTax, double? total, double? totalTax, bool? pricesIncludeTax, int? customerId, String? customerIpAddress, String? customerUserAgent, String? customerNote, WooBilling? billing, WooShipping? shipping, String? paymentMethod, String? paymentMethodTitle, String? transactionId, DateTime? datePaid, DateTime? datePaidGmt, DateTime? dateCompleted, DateTime? dateCompletedGmt, String? cartHash, List<WooMetaData>? metaData, List<WooLineItem>? lineItems, List<WooTaxLine>? taxLines, List<WooShippingLine>? shippingLines, List<WooOrderFeeLine>? feeLines, List<WooOrderCouponLine>? couponLines, List<WooRefunds>? refunds, bool? setPaid = false})
Creates a new WooOrder instance
WooOrder.fake()
Creates a fake WooOrder instance for testing purposes
factory
WooOrder.fromJson(Map<String, dynamic> json)
Creates a WooOrder instance from JSON data

Properties

billing WooBilling?
Billing address.
getter/setter pair
cartHash String?
MD5 hash of cart items to ensure orders are not modified.
getter/setter pair
cartTax double?
Sum of line item taxes only
getter/setter pair
couponLines List<WooOrderCouponLine>?
Coupon lines for the order.
getter/setter pair
createdVia String?
Source where the order was created
getter/setter pair
currency WooOrderCurrency?
Currency used for the order
getter/setter pair
customerId int?
User ID who owns the order. 0 for guests. Default is 0.
getter/setter pair
customerIpAddress String?
Customer's IP address.
getter/setter pair
customerNote String?
Note left by customer during checkout.
getter/setter pair
customerUserAgent String?
User agent of the customer.
getter/setter pair
dateCompleted DateTime?
The date the order was completed, in the site's timezone.
getter/setter pair
dateCompletedGmt DateTime?
The date the order was completed, as GMT.
getter/setter pair
dateCreated DateTime?
Date and time when the order was created (local time)
getter/setter pair
dateCreatedGmt DateTime?
Date and time when the order was created (GMT)
getter/setter pair
dateModified DateTime?
Date and time when the order was last modified (local time)
getter/setter pair
dateModifiedGmt DateTime?
Date and time when the order was last modified (GMT)
getter/setter pair
datePaid DateTime?
The date the order was paid, in the site's timezone.
getter/setter pair
datePaidGmt DateTime?
The date the order was paid, as GMT.
getter/setter pair
discountTax double?
Total discount tax amount for the order
getter/setter pair
discountTotal double?
Total discount amount for the order
getter/setter pair
feeLines List<WooOrderFeeLine>?
Fee lines for the order.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
id int?
Unique identifier for the order
getter/setter pair
lineItems List<WooLineItem>?
Line items in the order.
getter/setter pair
metaData List<WooMetaData>?
Custom order metadata.
getter/setter pair
number String?
Order number
getter/setter pair
orderKey String?
Order key
getter/setter pair
parentId int?
Parent order ID
getter/setter pair
paymentMethod String?
Payment method ID.
getter/setter pair
paymentMethodTitle String?
Payment method title.
getter/setter pair
pricesIncludeTax bool?
Whether prices included tax during checkout
getter/setter pair
refunds List<WooRefunds>?
List of refunds for the order.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
setPaid bool?
Define if the order is paid. It will set the status to processing and reduce stock items. Default is false.
getter/setter pair
shipping WooShipping?
Shipping address.
getter/setter pair
shippingLines List<WooShippingLine>?
Shipping lines for the order.
getter/setter pair
shippingTax double?
Total shipping tax amount for the order
getter/setter pair
shippingTotal double?
Total shipping amount for the order
getter/setter pair
status WooOrderStatus?
Order status
getter/setter pair
taxLines List<WooTaxLine>?
Tax lines for the order.
getter/setter pair
total double?
Grand total of the order
getter/setter pair
totalTax double?
Sum of all taxes applied to the order
getter/setter pair
transactionId String?
Unique transaction ID.
getter/setter pair
version String?
WooCommerce version that last updated the order
getter/setter pair

Methods

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

Operators

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