Filter uncanny-automator

automator_woocommerce_order_summary_show_payment_method

Filters whether to display the payment method on the WooCommerce order summary. Fires before the payment method is rendered.

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

Description

Filters whether to display the WooCommerce payment method in the order summary. Developers can use this to conditionally hide or show the payment method based on specific criteria. The first parameter defaults to `true`, indicating the payment method is shown.


Usage

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

Parameters

$order (mixed)
This parameter controls whether the payment method should be displayed in the order summary.

Return Value

The filtered value.


Examples

/**
 * Example callback function for the automator_woocommerce_order_summary_show_payment_method filter hook.
 *
 * This example demonstrates how to conditionally hide the payment method from the order summary
 * if the order total is above a certain amount and uses a specific payment gateway.
 *
 * @param bool   $show_payment_method Whether to show the payment method. Defaults to true.
 * @param WC_Order $order             The WooCommerce order object.
 *
 * @return bool The modified value for whether to show the payment method.
 */
function my_automator_hide_payment_method_for_large_orders( $show_payment_method, $order ) {
	// Only apply this logic if we're currently set to show the payment method.
	if ( ! $show_payment_method ) {
		return false;
	}

	// Define a threshold amount (e.g., $1000).
	$threshold_amount = 1000;

	// Define the payment gateway slug we want to target (e.g., 'stripe').
	$target_payment_method = 'stripe';

	// Check if the order total is greater than the threshold.
	if ( $order->get_total() > $threshold_amount ) {
		// Check if the order's payment method matches our target.
		if ( $order->get_payment_method() === $target_payment_method ) {
			// Hide the payment method for large orders using Stripe.
			return false;
		}
	}

	// Otherwise, return the original value (which is likely true).
	return $show_payment_method;
}

// Add the filter to WordPress.
// The '2' indicates that this callback function accepts 2 arguments:
// $show_payment_method (the filtered value) and $order (the order object).
add_filter( 'automator_woocommerce_order_summary_show_payment_method', 'my_automator_hide_payment_method_for_large_orders', 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:1104
src/integrations/wholesale-suite/tokens/wss-tokens.php:731
uncanny-automator-pro/src/integrations/woocommerce/tokens/wc-pro-tokens.php:3017

$html[] = $td_right;
				$html[] = wc_price( $order->get_total_tax() );
				$html[] = '</td>';
				$html[] = '</tr>';
			}
		}
		// Payment method
		if ( true === apply_filters( 'automator_woocommerce_order_summary_show_payment_method', true, $order ) ) {
			$html[] = '<tr>';
			$html[] = $td;
			$html[] = apply_filters( 'automator_woocommerce_order_summary_payment_method_title', esc_attr__( 'Payment method:', 'uncanny-automator' ) );
			$html[] = '</td>';
			$html[] = $td_right;
			$html[] = $order->get_payment_method_title();
			$html[] = '</td>';


Scroll to Top