Created
March 29, 2022 15:07
-
-
Save Garconis/45baddc26d0b7cdd1b88d6f334826f34 to your computer and use it in GitHub Desktop.
WooCommerce Subscriptions | Redirect subscriber with active WC subscription when logging in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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