• Hello,
    I found this code in this forum:

    function lgbk_add_member( $order_id ) {
    
    $order = new WC_Order( $order_id );
    $items = $order->get_items();
    
    foreach ( $items as $item ) {
        $product_name = $item['name'];
        $product_id = $item['product_id'];
        $product_variation_id = $item['variation_id'];
    
    if ( $order->user_id > 0 && $product_id == '33' ) {
    	update_user_meta( $order->user_id, 'paying_customer', 1 );
    	$user = new WP_User( $order->user_id );
    
    	// Remove role
    	$user->remove_role( 'subscriber' ); 
    
    	// Add role
    	$user->add_role( 'contributor' );
    	}
    
    }
    
    }
    add_action( 'woocommerce_order_status_completed', 'lgbk_add_member' );

    It is working great but as I have like 200 products in my shop, i guess it wouldn’t be good to copy this code for almost 50 products. So my question: Is there a way to achieve the same thing but not for a specific product but for more products like from a certain category or better with a specific keyword?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    Do you have find a solution Dune1982 ?
    I would like to do the same thing.

    Thanks for your expertise,
    Juliette

    Thread Starter dune1982

    (@dune1982)

    Hi,
    no up until now I have no solution. But if you should find something, please give me a hint.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WooCommerce Change User Role on Purchase of Product with a certain keyword (tag)’ is closed to new replies.