Filter uncanny-automator

automator_woocommerce_order_summary_line_item_title

Filters the title of a WooCommerce order summary line item before it's displayed.

add_filter( 'automator_woocommerce_order_summary_line_item_title', $callback, 10, 4 );

Description

Filters the title of a WooCommerce order line item before it's displayed. Developers can use this hook to modify the product title for specific needs within order summaries, potentially adding custom information or altering its presentation based on product or order details. The hook provides access to the product, item, and order objects.


Usage

add_filter( 'automator_woocommerce_order_summary_line_item_title', 'your_function_name', 10, 4 );

Parameters

$title (mixed)
This parameter represents the title of the order summary line item.
$product (mixed)
This parameter holds the current title of the order summary line item, which can be modified by the filter.
$item (mixed)
This parameter contains the WooCommerce product object associated with the order item.
$order (mixed)
This parameter contains the WC_Order_Item_Product object, representing a single line item within the WooCommerce order.

Return Value

The filtered value.


Examples

/**
 * Customize the order item title for the order summary.
 *
 * This example adds a prefix to the product title if it's a simple product,
 * or appends a specific string if it's a variation.
 *
 * @param string $title   The current title of the order item.
 * @param WC_Product $product The WC_Product object for the item.
 * @param WC_Order_Item_Product $item The order item object.
 * @param WC_Order $order The WC_Order object.
 * @return string The modified order item title.
 */
add_filter( 'automator_woocommerce_order_summary_line_item_title', function( $title, $product, $item, $order ) {

	// Check if it's a simple product and add a prefix
	if ( $product && ! $product->is_type( 'variation' ) ) {
		$title = 'Product: ' . $title;
	}

	// Check if it's a variation and append a specific indicator
	if ( $product && $product->is_type( 'variation' ) ) {
		$title .= ' (Customized)';
	}

	return $title;
}, 10, 4 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/integrations/woocommerce/tokens/wc-tokens.php:1056
src/integrations/wholesale-suite/tokens/wss-tokens.php:683
uncanny-automator-pro/src/integrations/woocommerce/tokens/wc-pro-tokens.php:2969

$product = $item->get_product();
				if ( true === apply_filters( 'automator_woocommerce_order_summary_show_product_in_invoice', true, $product, $item, $order ) ) {
					$html[] = '<tr class="order_item">';
					$title  = $product->get_title();
					if ( $item->get_variation_id() ) {
						$variation      = new WC_Product_Variation( $item->get_variation_id() );
						$variation_name = implode( ' / ', $variation->get_variation_attributes() );
						$title          = apply_filters( 'automator_woocommerce_order_summary_line_item_title', "$title - $variation_name", $product, $item, $order );
					}
					if ( true === apply_filters( 'automator_woocommerce_order_summary_link_to_line_item', true, $product, $item, $order ) ) {
						$title = sprintf( '<a style="color: %s; vertical-align: middle; padding: 12px 0; text-align: left;" href="%s">%s</a>', $td_text_colour, $product->get_permalink(), $title );
					}
					$html[] = sprintf( '%s %s</td>', $td, $title );
					$html[] = $td . $item->get_quantity() . '</td>';
					$html[] = $td . wc_price( $item->get_total() ) . '</td>';


Scroll to Top