Allow admin to view users wishlists
-
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.
- The topic ‘Allow admin to view users wishlists’ is closed to new replies.