Filter uncanny-automator

automator_woocommerce_order_summary_show_total

Filters whether to show the order total within the WooCommerce order summary.

add_filter( 'automator_woocommerce_order_summary_show_total', $callback, 10, 1 );

Description

Filters whether the order total should be displayed in the WooCommerce order summary. Developers can return `false` to hide the total. This hook fires after order meta is processed and before the order total is rendered.


Usage

add_filter( 'automator_woocommerce_order_summary_show_total', 'your_function_name', 10, 1 );

Parameters

$order (mixed)
This parameter is a boolean flag that controls whether the order total should be displayed in the order summary.

Return Value

The filtered value.


Examples

/**
 * Conditionally hide the order total in the Uncanny Automator WooCommerce order summary.
 *
 * This filter allows you to prevent the order total from being displayed in certain
 * scenarios, for example, if the order is for a free product or a specific type
 * of order where the total is not relevant.
 *
 * @param bool   $show_total Whether to show the order total. Default is true.
 * @param WC_Order $order      The WooCommerce order object.
 *
 * @return bool True to show the order total, false to hide it.
 */
add_filter( 'automator_woocommerce_order_summary_show_total', function( $show_total, $order ) {
	// Example: Hide the total if the order is for a free product (total is 0).
	if ( $order instanceof WC_Order && '0.00' === $order->get_formatted_order_total() ) {
		return false; // Do not show the total for free orders.
	}

	// Example: Hide the total for orders with a specific tag (e.g., 'internal_test').
	// You would need to implement logic to add such tags to orders if needed.
	// if ( $order instanceof WC_Order && $order->get_meta( 'order_tag' ) === 'internal_test' ) {
	// 	return false;
	// }

	// For all other cases, show the total.
	return $show_total;
}, 10, 2 );

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:1115
src/integrations/wholesale-suite/tokens/wss-tokens.php:742
uncanny-automator-pro/src/integrations/woocommerce/tokens/wc-pro-tokens.php:3028

$html[] = '</td>';
			$html[] = $td_right;
			$html[] = $order->get_payment_method_title();
			$html[] = '</td>';
			$html[] = '</tr>';
		}
		// Total
		if ( true === apply_filters( 'automator_woocommerce_order_summary_show_total', true, $order ) ) {
			$html[] = '<tr>';
			$html[] = $td;
			$html[] = apply_filters( 'automator_woocommerce_order_summary_total_title', esc_attr__( 'Total:', 'uncanny-automator' ) );
			$html[] = '</td>';
			$html[] = $td_right;
			$html[] = $order->get_formatted_order_total();
			$html[] = '</td>';


Scroll to Top