Woocommerce Redirect User Login to Homepage

I have searched for the answer to this, used plugins and still nothing works. I would like users of my site to be redirected to the home page after they login/register. Currently, the user logs in and is redirected to the my account page.

Woocommerce provides this code, but it failed to work for me:

redirect   
  1. /*
  2.  * goes in theme functions.php or a custom plugin
  3.  *
  4.  * By default login goes to my account
  5.  **/
  6. add_filter('woocommerce_login_widget_redirect', 'custom_login_redirect');
  7.  
  8. function custom_login_redirect( $redirect_to ) {
  9. $redirect_to = 'http://anypage.com';
  10. }

There has been a filter recently added to allow you to redirect after registration. Doing a redirect on login is as simple above (putting it in form-login.php). Here is a link to the filter and some instructions for handling this on the registration form.

Use this code on functions.php

  1. add_action('wp_logout','go_home');
  2. function go_home(){
  3. wp_redirect( home_url() );
  4. exit();
  5. }