Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce Subscriptions | Redirect subscriber with active WC subscription when logging in
<?php
function freshy_redirect_role($user_login, $user) {
//var_dump($user);
if( in_array( 'subscriber',$user->roles ) ){
//The next two lines are to check if the user has an active subscription
//in the Woocommerce Subscription plugin... if so redirect to custom path instead of WooCommerce default My Account page
if( function_exists( 'wcs_user_has_subscription' ) ) {
// Indicate whether a given user has a subscription to a given product with an optional status filter
// FYI: If the status filter is left empty, the function will see if the user has a subscription of any status
// check the user's ID, for any product ID, that has an active status ... if met returns true
if( wcs_user_has_subscription( $user->ID, '', 'active' ) ){
wp_redirect('/member-home/' ); exit;
}
}
}
}
add_action( 'wp_login', 'freshy_redirect_role', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment