Filter uncanny-automator

automator_woocommerce_order_summary_show_product_in_invoice

Filters whether to show a product in the WooCommerce order invoice summary, controlling its visibility.

add_filter( 'automator_woocommerce_order_summary_show_product_in_invoice', $callback, 10, 3 );

Description

This filter controls whether a product is displayed in WooCommerce order summaries, invoices, and related Automator tokens. Developers can return `false` to hide specific products or customize their display logic. It's particularly useful for excluding bundled items or items with custom display requirements.


Usage

add_filter( 'automator_woocommerce_order_summary_show_product_in_invoice', 'your_function_name', 10, 3 );

Parameters

$product (mixed)
This parameter determines whether the product should be displayed in the order summary for the invoice.
$item (mixed)
This parameter holds the WooCommerce product object that is currently being processed for the order summary.
$order (mixed)
This parameter provides the individual item from the order that is being processed for display on the invoice.

Return Value

The filtered value.


Examples

/**
 * Example of how to use the 'automator_woocommerce_order_summary_show_product_in_invoice' filter.
 *
 * This filter allows you to conditionally hide specific products from the order summary
 * shown within an Uncanny Automator WooCommerce trigger or action.
 *
 * For instance, you might want to hide internal products or products used for specific
 * subscription management purposes.
 *
 * @param bool    $show_product Whether to show the product in the invoice.
 * @param WC_Product $product    The WC_Product object.
 * @param WC_Order_Item_Product $item The order item object.
 * @param WC_Order $order The WC_Order object.
 *
 * @return bool Returns false to hide the product, true to show it.
 */
add_filter(
	'automator_woocommerce_order_summary_show_product_in_invoice',
	function ( $show_product, $product, $item, $order ) {
		// Example: Hide products with a specific SKU, e.g., "INTERNAL-USE-ONLY"
		$sku_to_hide = 'INTERNAL-USE-ONLY';

		if ( $product && $product->get_sku() === $sku_to_hide ) {
			return false; // Hide this product
		}

		// You could also add logic based on order meta, product category, etc.
		// For example, to hide products from a specific category:
		// $hide_category_slug = 'promotional-items';
		// $product_cats = wp_get_post_terms( $product->get_id(), 'product_cat', array( 'fields' => 'slugs' ) );
		// if ( in_array( $hide_category_slug, $product_cats ) ) {
		//     return false;
		// }

		// If no specific hiding logic is met, return the original value.
		return $show_product;
	},
	10, // Priority
	4  // Number of accepted arguments
);

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:1050
src/integrations/wholesale-suite/tokens/wss-tokens.php:677
uncanny-automator-pro/src/integrations/woocommerce/tokens/wc-pro-tokens.php:2963

'<td class="td" style="color: %s; border: 1px solid %s; padding: 12px; text-align: left; vertical-align: middle; font-family: %s">',
				$td_text_colour,
				$td_border_colour,
				$font_family
			);
			foreach ( $items as $item ) {
				$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 );
					}


Scroll to Top