Customizing the Order Items in SMS Notifications for WooCommerce with WP SMS

Updated on Feb 13, 2025

Filter

wp_sms_notification_woocommerce_order_item

By default, when you use the %order_items% variable (reference) in the SMS message templates, the purchased items in an order are displayed in the following format:

- ProductName x Quantity Price

For example, if a customer orders a product, the purchased item in the SMS looks like this:

- Product A x 2 $49.99

You can customize how order item details are displayed in the SMS using the wp_sms_notification_woocommerce_order_item filter.

Example Usage

To modify the order item data in the SMS notification, add the following hooks to the functions.php file of your active theme.

Basic Customization: Display Only the Product Name

add_filter('wp_sms_notification_woocommerce_order_item', function ($itemString, $orderItemData, $item, $order) {
    return "- {$orderItemData['name']}";
}, 10, 4);

Display the Item Name and the Quantity

add_filter('wp_sms_notification_woocommerce_order_item', function ($itemString, $orderItemData, $item, $order) {
    return "- {$orderItemData['name']} x {$orderItemData['quantity']}";
}, 10, 4);

Advanced Example: Display the SKU for Each Item

add_filter('wp_sms_notification_woocommerce_order_item', function ($itemString, $orderItemData, WC_Order_Item $item, $order) {
    $metaKey = '_sku'; // Change the meta key accordingly
    /** @var \WC_Product $product */
    $product = $item->get_product();
    $isVariation = $product->is_type('variation');
    $metaValue = null;

    // Check if the item is a variable product
    if ($isVariation) {
        $metaValue = $product->get_meta($metaKey);
        // Backward compatibility.
        if (!$metaValue) {
            $metaValue = get_post_meta($product->get_id(), $metaKey, true);
        }
    }

    if (!$metaValue) {
        $metaValue = $item->get_meta($metaKey);
        // Backward compatibility.
        if (!$metaValue) {
            $metaValue = get_post_meta($item->get_product_id(), $metaKey, true);
        }
    }
    return "- SKU: $metaValue | Item: $itemString";
}, 10, 4);