Logout Redirection

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Tagged: 

Viewing 12 reply threads
  • Author
    Posts
    • #124652
      eguareone
      Participant

      Hi Friends,

      Please how do I redirect vendors to a custom URL when they log out from the frontend manager? I found some tips online but none worked… Any help will be appreciated. Thanks.

    • #124689
      Sushobhan
      Keymaster

      Hi,
      Thanks for getting in touch with us!
      Please use the following snippet for your requirement-

      add_filter( 'wcfm_logout_url', function( $logout_url ) {
      	if( wcfm_is_vendor() ) {
      		return 'URL_YOU_WANT_TO_GET_REDIRECTED_TO'; // set your url here
        }
        return $logout_url;
      });
      
      add_filter('woocommerce_get_endpoint_url', function($url, $endpoint, $value, $permalink) {
          if($permalink === 'URL_YOU_WANT_TO_GET_REDIRECTED_TO') { // repeat the same url
              return $permalink;
          }
          return $url;
      }, 10, 4);

      Add this code to your child theme’s functions.php
      In case you do not have child theme then add code using this plugin – https://wordpress.org/plugins/code-snippets/
      Let me know how this goes.
      Thanks!

    • #125215
      eguareone
      Participant

      Hi thanks so much for your reply.

      I’m not to clear on where to place the custom url on the code

      Below is how i understand it. Custom url is https://abaaexpress.com.ng/seller-login

      add_filter( 'wcfm_logout_url', function( $logout_url ) {
      	if( wcfm_is_vendor() ) {
      		return 'https://abaaexpress.com.ng/seller-login'; // set your url here
        }
        return $logout_url;
      });
      
      add_filter('woocommerce_get_endpoint_url', function($url, $endpoint, $value, $permalink) {
          if($permalink === 'https://abaaexpress.com.ng/seller-login') { // repeat the same url
              return $permalink;
          }
          return $url;
      }, 10, 4);

      Did I do it right?

      Thanks again for your help.

    • #125468
      Sushobhan
      Keymaster

      Sorry! The code wasn’t working. It was redirecting you to that page and not logging you out. Here is the updated code-

      add_filter( 'wcfm_logout_url', function( $logout_url ) {
          if ( wcfm_is_vendor() ) {
              return 'https://abaaexpress.com.ng/seller-login/';
          }
          return $logout_url;
      } );
      add_filter( 'woocommerce_get_endpoint_url', function($url, $endpoint, $value, $permalink) {
          if ( $permalink === 'https://abaaexpress.com.ng/seller-login/' ) {
              return add_query_arg( 'wcfm_logout', 'yes', $permalink );
          }
          return $url;
      }, 10, 4 );
      function redirect_page() {
          global $wp;
          if ( ! empty( $_REQUEST['wcfm_logout'] ) && ! empty( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'customer-logout' ) ) {
              wp_safe_redirect( str_replace( '&', '&', wp_logout_url( esc_url_raw( 'https://abaaexpress.com.ng/seller-login/' ) ) ) );
              exit;
          }
      }
      add_action( 'template_redirect', 'redirect_page' );

      This should be a one line code but due to a known bug in WooCommerce, we have to take this ugly route!
      Let me know how it goes.
      Thank You!

    • #125763
      eguareone
      Participant

      Thank you for this! I’m afraid that this new code did not work. It gave the following error

      Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP.

      Please is there an alternative? I don’t want to use FTP

      Thank you

    • #126076
      Sushobhan
      Keymaster

      Hello,
      It’s not a good idea to edit anything without ftp. If anything goes wrong, like a fatal error, then you can’t recover it from frontend.
      To add snippets from wp-admin, use this plugin – https://wordpress.org/plugins/code-snippets/. It’s much better than editing theme’s functions.php using theme editor option.
      Finally, the error you are seeing, is not related to the code. If possible use the plugin I mentioned or ftp.
      Thanks!

    • #127874
      eguareone
      Participant

      Hello Sushobhan
      Thanks for the heads up and all your help so far. I finally tried the code, The logout redirection worked but not as you expected it to. When the vendor logs out from Store Manager, It gives them a prompt, something like “Do You really want to logout from “Website Url”? On confirmation, it redirects to the wordpress admin Login Url instead of the abaaexpress.com.ng/seller-login/

      Please I really need help with this as i’m not good with codes. Thanks again

    • #127898
      Sushobhan
      Keymaster

      It should work without the confirmation. I have again tested it on my local setup. Please check if you have pasted the complete code or not. Where you are pasting the code in functions.php or using the snippet plugin? Please send me a snapshot of the portion of the code.
      Alternatively, could you please provide me a temporary ftp along with a vendor access to debug this?
      Thank You!

    • #128180
      eguareone
      Participant

      Hi,

      I prefer the alternate measure. Please send me an email to abaaexpress@gmail.com so that I can forward the FTP and Vendor Login Access. Thanks

    • #145028
      server.monks123
      Participant

      Hello Sushobhan
      I also tried the code, The logout redirection worked but wen the vendor logs out from Store Manager, It gives them a prompt, something like “Do You really want to logout from “Website Url”? On confirmation, it redirects to the wordpress admin Login Url instead of the https://inditribes.co.in
      Please help me out

      Attachments:
      You must be logged in to view attached files.
    • #145718
      Sushobhan
      Keymaster

      Hi,
      Could you please send me the code snippet that you are using?
      Thanks!

    • #145770
      server.monks123
      Participant

      add_filter( ‘wcfm_logout_url’, function( $logout_url ) {
      if ( wcfm_is_vendor() ) {
      return ‘https://inditribes.co.in/’;
      }
      return $logout_url;
      } );
      add_filter( ‘woocommerce_get_endpoint_url’, function($url, $endpoint, $value, $permalink) {
      if ( $permalink === ‘https://inditribes.co.in/’ ) {
      return add_query_arg( ‘wcfm_logout’, ‘yes’, $permalink );
      }
      return $url;
      }, 10, 4 );
      function redirect_page() {
      global $wp;
      if ( ! empty( $_REQUEST[‘wcfm_logout’] ) && ! empty( $_REQUEST[‘_wpnonce’] ) && wp_verify_nonce( sanitize_key( $_REQUEST[‘_wpnonce’] ), ‘customer-logout’ ) ) {
      wp_safe_redirect( str_replace( ‘&’, ‘&’, wp_logout_url( esc_url_raw( ‘https://inditribes.co.in/’ ) ) ) );
      exit;
      }
      }
      add_action( ‘template_redirect’, ‘redirect_page’ );

    • #146104
      Sushobhan
      Keymaster

      Hi,
      The code seems correct. Not sure why it is behaving unexpectedly!
      Would you be comfortable sharing temporary backend access to your site, to debug this further?
      When sharing the access, please don’t forget to mark the reply as private.
      Thank you!

Viewing 12 reply threads
  • You must be logged in to reply to this topic.