Appearance
Order Meta Model
| DB Table Name | {wp_db_prefix}_fct_order_meta |
|---|---|
| Schema | Check Schema |
| Source File | fluent-cart/app/Models/OrderMeta.php |
| Name Space | FluentCart\App\Models |
| Class | FluentCart\App\Models\OrderMeta |
Attributes
| Attribute | Data Type | Comment |
|---|---|---|
| id | Integer | Primary Key |
| order_id | Integer | Reference to order |
| meta_key | String | Meta key name |
| meta_value | Text | Meta value (JSON or string) |
| created_at | Date Time | Creation timestamp |
| updated_at | Date Time | Last update timestamp |
Usage
Please check Model Basic for Common methods.
Accessing Attributes
php
$orderMeta = FluentCart\App\Models\OrderMeta::find(1);
$orderMeta->id; // returns id
$orderMeta->order_id; // returns order ID
$orderMeta->meta_key; // returns meta key
$orderMeta->meta_value; // returns meta valueScopes
This model has the following scopes that you can use
ofOrder($orderId)
Filter order meta by order ID
- Parameters
- $orderId - integer
Usage:
php
// Get all meta for a specific order
$orderMeta = FluentCart\App\Models\OrderMeta::ofOrder(123)->get();ofMetaKey($metaKey)
Filter order meta by meta key
- Parameters
- $metaKey - string
Usage:
php
// Get all order meta for a specific key
$orderMeta = FluentCart\App\Models\OrderMeta::ofMetaKey('billing_address')->get();ofMetaKeys($metaKeys)
Filter order meta by multiple meta keys
- Parameters
- $metaKeys - array
Usage:
php
// Get order meta for multiple keys
$orderMeta = FluentCart\App\Models\OrderMeta::ofMetaKeys(['billing_address', 'shipping_address'])->get();Relations
This model has the following relationships that you can use
order
Access the associated order
- return
FluentCart\App\Models\OrderModel
Example:
php
// Accessing Order
$order = $orderMeta->order;
// For Filtering by order relationship
$orderMeta = FluentCart\App\Models\OrderMeta::whereHas('order', function($query) {
$query->where('status', 'completed');
})->get();Methods
Along with Global Model methods, this model has few helper methods.
getMetaValueAttribute($value)
Get meta value as array or string (accessor)
- Parameters
- $value - mixed
- Returns
mixed
Usage
php
$metaValue = $orderMeta->meta_value; // Returns array if JSON, string otherwisesetMetaValueAttribute($value)
Set meta value from array or string (mutator)
- Parameters
- $value - array|object|string
- Returns
void
Usage
php
// Set array value (will be JSON encoded)
$orderMeta->meta_value = ['address' => '123 Main St', 'city' => 'New York'];
// Set string value
$orderMeta->meta_value = 'simple string value';getMetaValueAsArray()
Get meta value as array (force array return)
- Parameters
- none
- Returns
array
Usage
php
$metaArray = $orderMeta->getMetaValueAsArray();getMetaValueAsString()
Get meta value as string (force string return)
- Parameters
- none
- Returns
string
Usage
php
$metaString = $orderMeta->getMetaValueAsString();isJsonValue()
Check if meta value is JSON
- Parameters
- none
- Returns
boolean
Usage
php
$isJson = $orderMeta->isJsonValue();getDecodedValue()
Get decoded JSON value or original value
- Parameters
- none
- Returns
mixed
Usage
php
$decodedValue = $orderMeta->getDecodedValue();Common Meta Keys
Here are some common meta keys used in FluentCart:
Billing Information
billing_address- Billing address databilling_first_name- Billing first namebilling_last_name- Billing last namebilling_company- Billing companybilling_address_1- Billing address line 1billing_address_2- Billing address line 2billing_city- Billing citybilling_state- Billing statebilling_postcode- Billing postal codebilling_country- Billing countrybilling_phone- Billing phone numberbilling_email- Billing email
Shipping Information
shipping_address- Shipping address datashipping_first_name- Shipping first nameshipping_last_name- Shipping last nameshipping_company- Shipping companyshipping_address_1- Shipping address line 1shipping_address_2- Shipping address line 2shipping_city- Shipping cityshipping_state- Shipping stateshipping_postcode- Shipping postal codeshipping_country- Shipping countryshipping_phone- Shipping phone number
Order Information
order_notes- Order notescustomer_notes- Customer notesadmin_notes- Admin notespayment_method- Payment method usedpayment_method_title- Payment method display nametransaction_id- Payment transaction IDgateway_transaction_id- Gateway transaction IDgateway_order_id- Gateway order ID
Subscription Information
subscription_id- Associated subscription IDsubscription_status- Subscription statusnext_payment_date- Next payment datesubscription_interval- Subscription interval
Custom Fields
custom_field_*- Custom field values_custom_*- Custom meta fields
Usage Examples
Get Order Billing Address
php
$order = FluentCart\App\Models\Order::find(123);
$billingAddress = $order->meta()->where('meta_key', 'billing_address')->first();
if ($billingAddress) {
$address = $billingAddress->meta_value; // Returns array
echo $address['address_1'] . ', ' . $address['city'];
}Set Order Custom Meta
php
$order = FluentCart\App\Models\Order::find(123);
// Set custom meta
$order->meta()->updateOrCreate(
['meta_key' => 'custom_field'],
['meta_value' => ['value' => 'custom data', 'type' => 'text']]
);Get All Order Meta as Key-Value Array
php
$order = FluentCart\App\Models\Order::find(123);
$metaData = $order->meta()->pluck('meta_value', 'meta_key')->toArray();