Filter
uncanny-automator-pro
automator_woocommerce_item_added_skip_product_ids
Filters product IDs to skip when an item is added to a WooCommerce order.
add_filter( 'automator_woocommerce_item_added_skip_product_ids', $callback, 10, 3 );
Description
Filters the product IDs that should be skipped when an item is added to a WooCommerce order. Developers can return an array of product IDs to prevent specific items from triggering automations. This filter runs before checking if a product should be processed.
Usage
add_filter( 'automator_woocommerce_item_added_skip_product_ids', 'your_function_name', 10, 3 );
Parameters
-
$product_id(mixed) - This parameter is used to provide an initial array of product IDs that should be skipped, which can then be filtered further.
-
$item(mixed) - This parameter holds the ID of the product that was just added to the WooCommerce order.
-
$order(mixed) - This parameter contains the specific WooCommerce order item being added to the cart.
Return Value
The filtered value.
Examples
/**
* Example: Skip specific products from triggering Uncanny Automator's "Product added to order" trigger.
*
* This function hooks into 'automator_woocommerce_item_added_skip_product_ids' to provide a
* list of product IDs that should be ignored by the trigger.
*
* @param array $skip_product_ids An array of product IDs to skip.
* @param int $product_id The ID of the product just added to the order.
* @param object $item The WooCommerce order item object.
* @param object $order The WooCommerce order object.
*
* @return array The modified array of product IDs to skip.
*/
add_filter( 'automator_woocommerce_item_added_skip_product_ids', 'my_automator_skip_specific_products', 10, 4 );
function my_automator_skip_specific_products( $skip_product_ids, $product_id, $item, $order ) {
// Let's say we want to skip product IDs 123 and 456 from triggering automations.
$products_to_exclude = array( 123, 456 );
// Merge our custom exclusion list with any existing ones.
$skip_product_ids = array_unique( array_merge( $skip_product_ids, $products_to_exclude ) );
return $skip_product_ids;
}
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/triggers/anon-order-item-created.php:216
public function is_product_allowed( $product_id, $item, $order ) {
// Allow users to skip specific product ids
$skip_product_ids = apply_filters( 'automator_woocommerce_item_added_skip_product_ids', array(), $product_id, $item, $order );
if ( ! empty( $skip_product_ids ) && in_array( absint( $product_id ), $skip_product_ids, true ) ) {
return false;
}
// Allow users to skip specific product types
$skip_product_types = apply_filters( 'automator_woocommerce_item_added_skip_product_type', array(), $product_id, $item, $order );
if ( ! empty( $skip_product_types ) && in_array( $item->get_product()->get_type(), $skip_product_types, true ) ) {
return false;
}
return true;
}