• When a user complete an order I change his role from customer to vip_customer (custom role) with this code

    function wpa_120656_convert_paying_customer( $order_id ) {
    
        $order = new WC_Order( $order_id );
    
        if ( $order->user_id > 0 ) {
            update_user_meta( $order->user_id, 'paying_customer', 1 );
            $user = new WP_User( $order->user_id );
    
            // Remove role
            $user->remove_role( 'customer' ); 
    
            // Add role
            $user->add_role( 'vip_customer' );
        }
    }
    add_action( 'woocommerce_order_status_completed', 'wpa_120656_convert_paying_customer' );

    now , I need a way to rechange wp role to woocommerce customer after a trial period of 1 year.

    Can you Help me?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    You probably should store the current datestamp in user meta in the above function. (and update the datestamp anytime the user makes another purchase if this is not handled here) Then use wp_schedule_event() to run a daily routine to query for all VIPs whose datestamp is one year or older and demote any found back to plain old ‘customer’.

    Thread Starter lestatu2

    (@lestatu2)

    this is what I was looking for….can someone give me the code for this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change wp role after a trial period’ is closed to new replies.