Try the following that will be triggered each time an order gets "completed" status, checking if the current order has specific products from your defined Ids, allowing you to perform an action:
add_action('woocommerce_order_status_completed', 'action_on_order_status_completed', 10, 2 );
function action_on_order_status_completed( $order_id, $order ){
// Here below define your product id(s)
$products_ids = array('11', '12', '13', '14', '15','16');
$found = false; // Initializing
// Loop through order items
foreach ( $order->get_items() as $item ) {
if ( array_intersect([$item->get_product_id(), $item->get_variation_id()], $products_ids) ) {
$found = true;
break; // Stop the loop
}
}
if ( $found ) {
// HERE do your action
}
}
Code goes in functions.php file of your active child theme (or active theme). Tested and work.
Related: How to get WooCommerce order details
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…