2017-10-19 15 views

Répondre

0

Vous pouvez utiliser ce code

add_action('woocommerce_order_status_completed', 'misha_change_role_on_purchase'); 

function misha_change_role_on_purchase($order_id) { 

// get order object and items 
$order = new WC_Order($order_id); 
$items = $order->get_items(); 

$product_id = 55; // that's a specific product ID 

foreach ($items as $item) { 

     if($product_id == $item['product_id'] && $order->user_id) { 
      $user = new WP_User($order->user_id); 

      // Remove role 
      $user->remove_role('customer'); 

      // Add role 
      $user->add_role('subscriber'); 
     } 

} 

} 

Si vous voulez vérifier par catégorie, il suffit d'ajouter une condition avec has_term($category_id, 'product_cat', $item['product_id'])

+0

Great! Merci beaucoup –