• Resolved Kir 2012

    (@kir-2012)


    Hi I’ve looked everywhere for this and I think i’m just missing something.

    I would like to add a tab to every user’s UM profile to include all woocommerce products they have listed on my site.

    The easiest way I have come up with so far is to copy the posts tab and rename it products or something and change the post type to product. I can see where the posts.php / posts-single is, I can create a products.php and products-single, but how do I call this into the profile for just a couple of roles likfoe ‘shop’, but for all of my site users to see?

    Really appreciate any help or pointers
    Many thanks

Viewing 1 replies (of 1 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @kir-2012

    Do you want to show a profile tab to specific user roles viewing other member’s profile?

    You can check this example code that shows the Products tab to Editor and Subscribers only:

    /**
     * Adds a main tab to display forum activity in profile
     *
     * @param $tabs
     *
     * @return mixed
     */
    function um_custom_products_add_tab( $tabs ) {
    	$tabs['products'] = array(
    		'name'  => __( 'Products', 'ultimate-member' ),
    		'icon'  => 'um-faicon-store',
    	);
    
    	return $tabs;
    }
    add_filter( 'um_profile_tabs', 'um_custom_products_add_tab', 1000 );
    
    /**
     * Add tabs based on user
     *
     * @param $tabs
     *
     * @return mixed
     */
    function um_custom_products_tab( $tabs ) {
    	if ( empty( $tabs['products'] ) ) {
    		return $tabs;
    	}
    
    	$user_id = um_user( 'ID' );
    	if ( ! $user_id ) {
    		return $tabs;
    	}
    
    	
    	$current_user_id = get_current_user_id();
    	um_fetch_user( $current_user_id );
        
    	// Don't show products if current user's role is not Editor or Subscriber
    	if ( ! in_array( um_user( 'role' ),['editor','subscriber'] ) ) {
    		unset( $tabs['products'] );
    	}
    
    	return $tabs;
    }
    add_filter( 'um_user_profile_tabs', 'um_custom_products_tab', 1000, 1 );
    
    /**
     * Default tab
     *
     * @param $args
     */
    function um_custom_products_default_tab_content( $args ) {
    	
    	echo "Show products to 'Subscriber' and 'Editor' only";
    }
    add_action( 'um_profile_content_products_default', 'um_custom_products_default_tab_content', 10, 1 );
    

    Let me know if this doesn’t work for you. Feel free to re-open this thread by changing the topic status to “Not Resolved”.

    Regards,

Viewing 1 replies (of 1 total)
  • The topic ‘Copy & amend posts tab to add additional tab with CPTS (not replace posts)’ is closed to new replies.