IN WooCommerce, I would like to perform an action if at least one product from a list is bought and if the current order status for that product is completed.
For instance I can only verify if the product is bought:
global $woocommerce;
$user_id = get_current_user_id();
$current_user= wp_get_current_user();
$product_list = array('11', '12', '13', '14', '15','16');
$text= false;
foreach ($product_list as $value):
if (wc_customer_bought_product( $customer_email, $user_id, $value) ) {
$text = true;
}
endforeach;
Try the following hooked function, that will be triggered each time an order gets "completed" status, checking if the current order has a product from your defined list, allowing you to perform an 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