Last active
August 29, 2015 14:09
-
-
Save smeric/0c425adf9e9439e3c076 to your computer and use it in GitHub Desktop.
Redirect WooCommerce customer to profile page after a successful login through wp-login.php
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 | |
/** | |
* Redirect WooCommerce customer to profile page after a successful login through wp-login.php or | |
* redirect any unauthorised user trying to access any wp-admin files. | |
* | |
* @author Sébastien Méric <[email protected]> | |
* @param string $redirect_to URL to redirect to. | |
* @return string | |
*/ | |
add_action( 'init', 'woocommerce_custom_redirect_customer_to_account_page' ); | |
function woocommerce_custom_redirect_customer_to_account_page() { | |
if ( is_admin() && ! current_user_can( 'edit_posts' ) && | |
! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { | |
$redirect_to = home_url(); | |
$myaccount_page_id = get_option( 'woocommerce_myaccount_page_id' ); | |
if ( $myaccount_page_id ) { | |
$redirect_to = get_permalink( $myaccount_page_id ); | |
} | |
wp_redirect( $redirect_to ); | |
exit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment