• Today I came up with a way to view the wishlists of other users. It’s not the prettiest, and I’d like to make it work with wp_dropdown_users, but that’ll have to be for another day.

    To start, open your themes functions.php file and add the following:

    function add_query_vars_filter( $vars ){
      $vars[] = "wishlistuserid";
      return $vars;
    }
    add_filter( 'query_vars', 'add_query_vars_filter' );

    This code will allow you to pass a URL parameter with the user_id of the user whose wishlist you want to view.

    Next, copy the wishlist template file from /wp-content/plugins/yith-woocommerce-wishlist/templates/wishlist.php to your theme directory. For example, I copied the file to /wp-content/themes/mytheme/page-admin_wishlist_viewer.php

    Then open the newly copied file and, change this:

    /**
     * Wishlist page template
     *
     * @author Your Inspiration Themes
     * @package YITH WooCommerce Wishlist
     * @version 1.0.6
     */

    to this:

    /**
     * Template Name: Admin Wishlist Viewer
     * Wishlist page template
     *
     * @author Your Inspiration Themes
     * @package YITH WooCommerce Wishlist
     * @version 1.0.6
     */

    Also in this file, replace this:

    if( isset( $_GET['user_id'] ) && !empty( $_GET['user_id'] ) ) {
        $user_id = $_GET['user_id'];
    } elseif( is_user_logged_in() ) {
        $user_id = get_current_user_id();
    }

    With this:

    if( isset( $_GET['user_id'] ) && !empty( $_GET['user_id'] ) ) {
          $user_id = esc_attr($wp_query->query_vars['wishlistuserid']);
    } elseif( is_user_logged_in() ) {
          $user_id = esc_attr($wp_query->query_vars['wishlistuserid']);
    }

    Finally, create a new Page and select the template you created (“Admin Wishlist Viewer”). SET THIS PAGE TO “PRIVATE”! Update the page. View the page and you won’t see any products.

    Now for the magic… Pass a variable to the page of the user_id of the user whose wishlist you’d like to view. For example, to view the wishlist for the user with the user_id=5, enter the URL of the page you created and append the following after the URL:

    ?wishlistuser=5

    So if I created a new page named “Admin Wishlist Viewer”, and if the permalink for the page were:
    http://mywebsite.com/admin-wishlist-viewer/
    To view the wishlist for user_id 5, I’d change the URL to:
    http://mywebsite.com/admin-wishlist-viewer/?wishlistuser=5

    YMMV. Let me know what you think.

    http://wordpress.org/plugins/yith-woocommerce-wishlist/

Viewing 1 replies (of 1 total)
  • It didn´t work for me. When I have the template wishlist.php on my theme folder, it breaks the regular wishlist page. No products show there. If you rename to anything else, it works again.

    Besides that, I put the user id of a test user as you instructed and didn´t show anything. I just figured out why. You told us to pass the wrong variable. It should be http://mywebsite.com/admin-wishlist-viewer/?wishlistuserid=5
    Please note the ID at the end of wishlistuser word.

    So, at the end, it works partially. I can see the users lists, but if I set up to do so, the users can´t see their own lists.

    All in all, thanks for trying to hack, but it would need some fixing so we don´t disturb the customers experience.

Viewing 1 replies (of 1 total)
  • The topic ‘Allow admin to view users wishlists’ is closed to new replies.