Filter uncanny-automator

automator_woocommerce_order_summary_show_subtotal

Filters whether to show the subtotal on the WooCommerce order summary, allowing custom control.

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

Description

This filter controls whether the order subtotal is displayed in WooCommerce order summaries within Uncanny Automator. Developers can use this hook to conditionally hide or show the subtotal based on specific order or user criteria, offering granular control over order detail presentation.


Usage

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

Parameters

$order (mixed)
This parameter controls whether the subtotal should be displayed on the order summary.

Return Value

The filtered value.


Examples

add_filter( 'automator_woocommerce_order_summary_show_subtotal', 'my_automator_hide_order_subtotal', 10, 2 );

/**
 * Hides the order subtotal from the Uncanny Automator order summary for specific orders.
 *
 * This filter allows you to conditionally hide the subtotal based on order details.
 * For example, you might hide it for orders where a specific coupon is applied.
 *
 * @param bool   $show_subtotal The current value indicating whether to show the subtotal.
 * @param WC_Order $order         The WooCommerce order object.
 *
 * @return bool Returns false to hide the subtotal, true to show it.
 */
function my_automator_hide_order_subtotal( $show_subtotal, $order ) {
	// Check if the order object is valid and if a specific coupon is applied.
	if ( $order instanceof WC_Order && $order->get_coupon_codes() ) {
		// Example: Hide subtotal if the 'free_shipping' coupon is used.
		if ( in_array( 'free_shipping', $order->get_coupon_codes() ) ) {
			return false; // Hide the subtotal
		}
	}

	// If no specific conditions are met, return the original value.
	return $show_subtotal;
}

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:1080
src/integrations/wholesale-suite/tokens/wss-tokens.php:707
uncanny-automator-pro/src/integrations/woocommerce/tokens/wc-pro-tokens.php:2993

);
		$td_right = sprintf(
			'<td class="td" style="color: %s; border: 1px solid %s; vertical-align: middle; padding: 12px; text-align: left; border-top-width: 4px;">',
			$td_text_colour,
			$td_border_colour
		);
		// Subtotal
		if ( true === apply_filters( 'automator_woocommerce_order_summary_show_subtotal', true, $order ) ) {
			$html[] = '<tr>';
			$html[] = $td;
			$html[] = apply_filters( 'automator_woocommerce_order_summary_subtotal_title', esc_attr__( 'Subtotal:', 'uncanny-automator' ) );
			$html[] = '</td>';
			$html[] = $td_right;
			$html[] = $order->get_subtotal_to_display();
			$html[] = '</td>';


Scroll to Top