Filter
uncanny-automator-pro
uap_option_all_wc_statuses
Filters the WooCommerce order statuses used by the plugin, allowing modification of available options.
add_filter( 'uap_option_all_wc_statuses', $callback, 10, 1 );
Description
This filter hook allows developers to modify the WooCommerce order status options available within Uncanny Automator Pro. It fires when the options are being generated, enabling developers to add, remove, or alter available statuses for triggers and actions, ensuring precise automation based on specific order states.
Usage
add_filter( 'uap_option_all_wc_statuses', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter is used to hold the data for the WooCommerce subscription statuses that will be used in the Uncanny Automator options.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the 'uap_option_all_wc_statuses' filter hook
* to modify the available WooCommerce order statuses displayed in Uncanny Automator.
*
* This example adds a custom status (if it exists in WooCommerce) to the list
* and potentially modifies the label of an existing status.
*/
add_filter( 'uap_option_all_wc_statuses', function( $option ) {
// Check if the current option is the one we want to modify (related to WC statuses).
// This is a safeguard, assuming the $option array contains an 'option_code' key.
if ( isset( $option['option_code'] ) && $option['option_code'] === 'wc_order_status' ) {
// Get the existing WooCommerce order statuses.
// wc_get_order_statuses() returns an array like:
// array(
// 'wc-pending' => _x( 'Pending Payment', 'Order status', 'woocommerce' ),
// 'wc-processing' => _x( 'Processing', 'Order status', 'woocommerce' ),
// // ... and so on
// );
$woocommerce_statuses = wc_get_order_statuses();
// Define a custom status we might want to add.
// Ensure this status actually exists in your WooCommerce installation.
$custom_status_slug = 'wc-on-hold'; // Example: Using an existing but perhaps less common status.
$custom_status_label = 'On Hold (Customized)';
// Add the custom status if it exists in WooCommerce and is not already present.
if ( isset( $woocommerce_statuses[ $custom_status_slug ] ) && ! array_key_exists( $custom_status_slug, $option['options'] ) ) {
$option['options'][ $custom_status_slug ] = $custom_status_label;
}
// Example of modifying an existing status label.
// Let's say we want to make 'Completed' more prominent.
$completed_status_slug = 'wc-completed';
if ( isset( $option['options'][ $completed_status_slug ] ) ) {
$option['options'][ $completed_status_slug ] = 'Order Successfully Completed!';
}
// You could also remove statuses if needed:
// unset($option['options']['wc-cancelled']);
}
// Always return the modified $option array.
return $option;
}, 10, 1 ); // Priority 10, accepting 1 argument.
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/helpers/woocommerce-pro-helpers.php:1148
public function get_wcs_statuses( $label = null, $option_code = 'WOOSUBSCRIPTIONSTATUS', $is_any = true ) {
if ( ! $label ) {
$label = esc_html_x( 'Status', 'Woocommerce', 'uncanny-automator' );
}
$statuses = wcs_get_subscription_statuses();
$options = array();
if ( true === $is_any ) {
$options['-1'] = esc_html_x( 'Any status', 'WooCommerce', 'uncanny-automator-pro' );
}
$options = $options + $statuses;
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'options' => $options,
);
return apply_filters( 'uap_option_all_wc_statuses', $option );
}