I once saw a sentence: 


  I will go to a restaurant for pie.


Native speakers didn't correct this sentence. I don't know why. I would say "I will go to a restaurant to eat a pie". But maybe that sentence was right. Could you please explain to me what that (first) sentence means?


Question: Woocommerce: change user role after completing order
Answer: Looking through the code there is a very relevant example:

function woocommerce_paying_customer( $order_id ) {

    $order = new WC_Order( $order_id );

    if ( $order-&gt;user_id &gt; 0 ) {

        $old_spent = absint( get_user_meta( $order-&gt;user_id, '_money_spent', true ) );
        update_user_meta( $order-&gt;user_id, '_money_spent', $old_spent + $order-&gt;order_total );

        $old_count = absint( get_user_meta( $order-&gt;user_id, '_order_count', true ) );
        update_user_meta( $order-&gt;user_id, '_order_count', $old_count + 1 );
    }
}
add_action( 'woocommerce_order_status_completed', 'woocommerce_paying_customer' );


which reminds us that the $order_is passed to the woocommerce_order_status_completed hook. From the $order_id, you can create a new order object, with the user_id as a property.

Armed with that knowledge, I think we can just fix the inner guts of the function get a new user object from that user ID, and remove the old role and finally apply the new role.

function wpa_120656_convert_paying_customer( $order_id ) {

    $order = new WC_Order( $order_id );

    if ( $order-&gt;user_id &gt; 0 ) {
        update_user_meta( $order-&gt;user_id, 'paying_customer', 1 );
        $user = new WP_User( $order-&gt;user_id );

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

        // Add role
        $user-&gt;add_role( 'subscriber' );
    }
}
add_action( 'woocommerce_order_status_completed', 'wpa_120656_convert_paying_customer' );