Automatically Change User Role After x Days
-
I’m currently using the User Role Editor plugin along with a function that upgrades a user’s role when they purchase a specific product from the site’s WooCommerce shop. The function to upgrade the user role is:
add_action( 'woocommerce_order_status_completed', 'upgrade_user_role' ); function upgrade_user_role( $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 == '3156' ) { 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( 'magazine-subscriber' ); } }
I would like to modify or add to this function so that after so many days the user role that was added (in this case magazine-subscriber) is removed and the only way to get it back is to buy the product again. I would like to avoid having to install any paid plugins if possible, but would consider it if necessary.
If anyone has any advice on how to achieve this I would really appreciate it!
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Automatically Change User Role After x Days’ is closed to new replies.