WooCommerce Order Items in SMS
Customize how order items are displayed in WooCommerce SMS notifications.
The %order_items% variable in WooCommerce SMS notifications displays purchased items. You can customize the format using the wp_sms_notification_woocommerce_order_item filter.
Default Format
By default, order items display as:
- ProductName x Quantity Price
Example: - Product A x 2 $49.99
Filter
add_filter('wp_sms_notification_woocommerce_order_item', 'your_callback', 10, 4);
Parameters
| Parameter | Type | Description |
|---|---|---|
$itemString | string | The default formatted item string |
$orderItemData | array | Item data (name, quantity, etc.) |
$item | WC_Order_Item | The order item object |
$order | WC_Order | The order object |
Examples
Display Product Name Only
add_filter('wp_sms_notification_woocommerce_order_item', function($itemString, $orderItemData, $item, $order) {
return "- {$orderItemData['name']}";
}, 10, 4);
Display Name and Quantity
add_filter('wp_sms_notification_woocommerce_order_item', function($itemString, $orderItemData, $item, $order) {
return "- {$orderItemData['name']} x {$orderItemData['quantity']}";
}, 10, 4);
Include SKU
add_filter('wp_sms_notification_woocommerce_order_item', function($itemString, $orderItemData, $item, $order) {
$product = $item->get_product();
$sku = $product->get_sku();
return "- [{$sku}] {$orderItemData['name']} x {$orderItemData['quantity']}";
}, 10, 4);
Advanced: SKU with Variation Support
add_filter('wp_sms_notification_woocommerce_order_item', function($itemString, $orderItemData, WC_Order_Item $item, $order) {
$product = $item->get_product();
$isVariation = $product->is_type('variation');
$sku = null;
if ($isVariation) {
$sku = $product->get_meta('_sku');
if (!$sku) {
$sku = get_post_meta($product->get_id(), '_sku', true);
}
}
if (!$sku) {
$sku = $item->get_meta('_sku');
if (!$sku) {
$sku = get_post_meta($item->get_product_id(), '_sku', true);
}
}
return "- SKU: {$sku} | {$itemString}";
}, 10, 4);
Compact Format
add_filter('wp_sms_notification_woocommerce_order_item', function($itemString, $orderItemData, $item, $order) {
return "{$orderItemData['name']}({$orderItemData['quantity']})";
}, 10, 4);
Use Cases
- Shorten item display to fit SMS character limits
- Include SKU or product codes
- Add custom product attributes
- Format prices differently
- Include variation details
Related
- WooCommerce Order Meta - Customize order metadata in SMS
- WooCommerce Tracking Notifications
Last updated: December 23, 2024