Filter
uncanny-automator-pro
automator_woocommerce_item_added_skip_product_type
Filters whether to skip adding a WooCommerce product to an Automator trigger based on its product type.
add_filter( 'automator_woocommerce_item_added_skip_product_type', $callback, 10, 3 );
Description
Filters which product types should be skipped by the "An order item is created" trigger. Developers can return an array of product type slugs (e.g., 'simple', 'variable') to prevent the trigger from firing for those product types, offering granular control over automation.
Usage
add_filter( 'automator_woocommerce_item_added_skip_product_type', 'your_function_name', 10, 3 );
Parameters
-
$product_id(mixed) - This parameter is an array used to store product IDs that should be skipped.
-
$item(mixed) - This parameter contains the ID of the product that was added to the order.
-
$order(mixed) - This parameter contains the WooCommerce order object associated with the added item.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the 'automator_woocommerce_item_added_skip_product_type' filter hook.
*
* This example will skip adding a trigger if the product added to the order is a 'variable' product type.
* This could be useful if you only want to trigger automations for simple products.
*
* @param array $skip_product_types An array of product types to skip.
* @param int $product_id The ID of the product added to the cart.
* @param WC_Order_Item_Product $item The order item object.
* @param WC_Order $order The order object.
* @return array The modified array of product types to skip.
*/
add_filter( 'automator_woocommerce_item_added_skip_product_type', function( $skip_product_types, $product_id, $item, $order ) {
// Check if the product type is 'variable' and add it to the skip list.
// Note: In a real-world scenario, you might want to check if the product_id and item are valid.
if ( $item instanceof WC_Order_Item_Product && $item->get_product() ) {
if ( $item->get_product()->get_type() === 'variable' ) {
$skip_product_types[] = 'variable';
}
}
// Return the potentially modified array of product types to skip.
return $skip_product_types;
}, 10, 4 ); // 10 is the priority, 4 is the number of accepted arguments.
?>
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:222
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;
}