Filter uncanny-automator-pro

automator_woocommerce_get_shipping_methods_order_fields

Filters the shipping methods for subscription orders, allowing modification before they are displayed.

add_filter( 'automator_woocommerce_get_shipping_methods_order_fields', $callback, 10, 2 );

Description

Fires after Uncanny Automator retrieves all available WooCommerce shipping methods. Developers can filter the `$formatted_methods` array to add, remove, or modify shipping method options available for use in Uncanny Automator triggers and actions. This hook allows for dynamic customization of shipping method selections.


Usage

add_filter( 'automator_woocommerce_get_shipping_methods_order_fields', 'your_function_name', 10, 2 );

Parameters

$formatted_methods (mixed)
This parameter contains the array of shipping methods that have been formatted for use within the Uncanny Automator plugin.
$this (mixed)
This parameter contains an array of shipping methods formatted for use in Uncanny Automator order fields.

Return Value

The filtered value.


Examples

/**
 * Example of how to filter the shipping methods available in Uncanny Automator for WooCommerce orders.
 * This example will remove the "Flat rate" shipping method from the list if it's present.
 */
add_filter( 'automator_woocommerce_get_shipping_methods_order_fields', function( $formatted_methods, $object ) {
    // Ensure we are dealing with an array and the object is what we expect (optional, but good practice)
    if ( ! is_array( $formatted_methods ) || ! is_a( $object, 'Automator_WooCommerce_Order_Fields' ) ) {
        return $formatted_methods;
    }

    // Iterate through the shipping methods and remove any that match "Flat rate"
    foreach ( $formatted_methods as $key => $method ) {
        // Assuming the method title is stored in the 'label' key
        if ( isset( $method['label'] ) && 'Flat rate' === $method['label'] ) {
            unset( $formatted_methods[ $key ] );
        }
    }

    // Re-index the array to ensure clean keys after unsetting
    return array_values( $formatted_methods );
}, 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

uncanny-automator-pro/src/integrations/woocommerce-subscription/fields/order-fields.php:148

public function get_shipping_methods() {
		$formatted_methods = array_merge(
			$this->get_default_options(),
			$this->get_zone_shipping_options(),
			$this->get_standard_shipping_options()
		);

		return apply_filters(
			'automator_woocommerce_get_shipping_methods_order_fields',
			$formatted_methods,
			$this
		);
	}


Scroll to Top