Global Product Categories Solved! A tutorial

With some help from other users and WPMU DEV staff, I’ve able to successfully complete control over product categories on a multisite network. I’m posting this in the hopes so that Aaron can mark it off his list of things to do. If it can be done using a workaround like this, then I think he shouldn’t devote his time to coding it in. This work around is easy and has multiple benefits.

There are two parts to this. The first section covers new multisite setups (or setups with no existing subsite stores/products). The first section will describe to ensure that all new stores/sites will have your declared product categories embedded in them the moment they are created.It also describes how to prevent any new product categories from being added by sellers. The second section will describe a method to clean up the mess created by existing stores with their own categories and tags.

PART 1: BASIC SETUP

~ Step 1. Decide what your categories are going to be ~

This is important, make a list and keep it handy, if you have to do Part 2 of this instruction, you’ll entering this list of categories in two places

~ Step 2. Create a New Blog Template ~

For multisite operators, this should be an essential thing to do. It allows you to brand any new sites on your network, as well as set them up in a way that is compatible with how you envision your network.

Use the WPMU Plugin for this: https://premium.wpmudev.org/project/new-blog-template

When setting up the template, activate the Marketpress plugin, then manually add all of the product categories you decided on in step 1. This will add them to the database for that blog. We use MP as a supporter plugin, if you do that, its okay to deactivate MP once the product categories have been added. They will still be there and will also be present on any new blogs (they will appear as default categories when MP gets activated on new blogs).

~ Step 3. Remove the +Add New Product Category link ~

The product pages in the admin allow users to add new product categories. This is a default of WordPress. You need to hide that link with specific css. This is done by styling your multisite admin area. To do this, you need to create two new files inside you mu-plugins directory.

Create a new mu-plugin called style-wp-admin.php and enter the following code. This new plugin will allow you to style you wp-admin area network-wide as you like:

<?php
/*
Plugin Name: My Admin Theme
Plugin URI:
Description: Load wp-admin.css from this same folder in order to style the admin area.
Author:
Version: 0.1
Author URI:
*/

function style_wp_admin() {
echo '<link rel="stylesheet" type="text/css" href="' .plugins_url('wp-admin.css', __FILE__). '">';
}

// Call the function above
add_action('admin_head', 'style_wp_admin');
?>

Next, also in mu-plugins, create wp-admin.css. This is the file you can now use to style your admin area. You can use this as you like from now own, but for this particular tutorial, you need to add this code to hide the link:

#product_category-add-toggle {
display: none;
visibility: hidden;
}

~ Step 4. Hide the Product Categories Menu Item ~

We use Admin Menu Editor plugin to keep the dashboard menus tidy for our users accross the network. This was a natural tool to use for this task. We simply changed the permissions for the Product Categories to Super Admin and moved it to a private menu we have for Super Admins only.

All Done! You have now gained complete control over product categories and they will be deployed globally across your network, ***but only on new sites.****

PART 2: CLEANING UP THE MESS

If you had a situation like us, you might have had sellers creating their own product categories which may leave you with a lot of different and interesting categories. You are going to have to go through to each site and clean things up. This part will tell you how.

~ Step 1a. Delete all existing categories ~

Go to all the store sites with existing product categories and delete all the categories your sellers have created. I loaded them all up in different tabs in the browser and went through each one and cleared them out. Keep these tabs open, you’ll need them again later.

~ Step 1b. Delete the categories from the marketplace table in the database ~

When someone creates a category it gets saved to wp_mp_terms in your database. You need to go to that table and delete any entry that is a product_category type. I also emptied the wp_mp_term_relationships table while I was at it. The data in these tables is a duplicate of data saved on the blogs, you aren’t killing anything that won’t be created again.

~ Step 2. Push your decided categories out to the network ~

Here, you will add your product categories to every site on your network. This is on the chance that any blog in time might become a store. You need the Network Terminator plugin for this. It works flawlessly and instantly and supports custom post types. You have to put it in yourself. Create a new folder in your plugin folder called network-terminator and put in it the file found here: https://github.com/maugly/Network-Terminator/blob/master/mau_network_terminator.php

Network Activate and you are ready to go. Simply select all the blogs in the network, add in your chosen product categories and send them out. It doesn’t matter if those blogs have MarketPress active on them or not, the categories will still be added and will be ready in case they are needed in the future. I was really impressed at how well this worked.

~ Step 4. Clean up clean up taxonomy conflicts ~

Categories and tags are simply taxonomies. They are stored in the same table and differentiated by type. However, being taxonomies, they cannot have the same slugs. If one of the existing blogs already has a tag with slug the same as one of your categories, the your new category won’t get added. It doesn’t get the -2, it just won’t be there. This is the most time consuming part.

You need to go to each blog and confirm that your product category was successfully added. I did this by checking each one under quick edit. If I found a blog that was missing one of my categories, I then had to screen through (using quick edit) all the tags on that blog to find the offender and delete it. Once the tag that is blocking your category out has been deleted, you should be able to add the category.

Given they way people are liberal with tags, this may take a while. It is labor intensive, but once you get it under control, if you properly implemented the setup in Part 1, you will never have to do this again.

~Step 5. Assign products to categories ~

The last thing you have to do, is reassign all your seller’s products to your new categories. This step is more essential than it appears on the surface. Up above, in Step1a I had you delete all the categories, this made all the product uncategorized, and then you deleted all the product categories from the database. In order to repopulate the database table (it is this table which powers your global product categories and tags widget) you need to reassign and resave everything. Saving them adds them back into that table.

Go through each blog, assign each product to your appropriate categories and save. This can be done using quick-edit. It was during this process that I discovered most of my taxonomy conflicts. If you didn’t find them manually, then it will become obvious here because when you sort by category in your marketplace, the product just won’t be there. Tracking down and removing those taxonomy conflicts is essential.

DONE!

It is some work to get this done, but the result is well worth it. When your sellers activate Marketpress and start adding products it makes your network look very professional and prepared.

Fondeli contributed a lot information to the method in making this happen and deserves a lot of credit. to my knowledge she was one of the first ones to get global product categories working. Additionally, she uses custom template files to sort and order the global categories in the marketplace. I haven’t done this yet, but hopefully, she’ll come by this thread and add her two cents.

  • DavidM
    • DEV MAN’s Mascot

    That is simply brilliant! There were other votes added to that previous thread on global product categories and I imagine there are others interested in the same too, so this will no doubt be greatly used.

    Many thanks to yourself and Fondeli for doing this! I’ll mention this to some of the other guys too, I’m sure they’ll be interested the idea, especially as it shows yet another possibility for MarketPress use. :slight_smile:

    Thanks,

    David

  • Saunt Valerian
    • The Bug Hunter

    As an addendum to Step 5, Part 2 – when it came down to tracking down taxonomy conflicts, I found it useful to completely empty the wp_mp_terms table. Resaving the products adds the tags and categories back to that table. By emptying, I was able to resave each product one-at-a-time and then look into the table to see how successful it was in adding the tags and categories. When the category wasn’t added, I knew I still had a taxonomy conflict.

  • Saunt Valerian
    • The Bug Hunter

    @byronmarkets – what you are talking about is a global products page. That is something else entirely and you can find multiple threads in here about setting it up.

    @anson – If you decided to add a new category later on, you’ll have to make use of the Network Terminator plugin to push it out to existing blogs. The new blog template will take care of new sites, but for any that were created without the use of the template, you need to use the plugin to push it.

  • Byronmarkets
    • Flash Drive

    Hiya,

    The start of this blog mentions that Fondeli used template files to sort and order global categories on the main marketplace site of her website. However I am struggling to workout how to do this – and find info on it, what I have found in the marketpress theming files, helps but it presumes previous knowledge of setting up template files. And the basic info on wordpress.org does not address the depth needed her.

    Could someone point me in the right direction for more detailed info on setting up product page templates for things such as the shopping cart, product categories especially global categories etc.

    Thank you in advance :slight_smile:

  • aseabridge
    • Flash Drive

    Hi,

    Firstly I would just like to say thanks for for this tutorial, it has been a great help!

    The only thing I am struggling with is step 4. admin menu editor (http://wordpress.org/extend/plugins/admin-menu-editor/). I have installed it and network enabled it but it doesn’t apply to my networks. I have hidden pretty much everything in the admin area from anyone but super admins but if I login as a store manager I can see all options still. I can’t see any settings for the menu in the network admin area. I have read about activating this on supporter sites but I don’t have supporter sites I don’t think. I am using WP + Multisite + Marketpress.

    Any ideas?

    Thanks

    Adam

  • Alex
    • Design Lord, Child of Thor

    I installed admin menu editor. It works really well.

    Did you make sure to install it under /wp-content/mu-plugins/?

    Also need to move admin-menu-editor-mu.php from admin-menu-editor/includes to /wp-content/mu-plugins/

  • PurpleTye
    • Flash Drive

    Unfortunately this has not worked for me. When I uploaded the files style_wp_admin.php and wp-admin.css to the mu-plugin folder, it broke numerous links within my site. I couldn’t use the admin menu editor plugin or even log out of my site. I also had the same issue with the network terminator plugin. :disappointed:

  • applemarketing
    • Site Builder, Child of Zeus

    Thank you very much for this tutorial! I used this and was successful in pushing the same categories in both existing blogs and new blogs from a template.

    Then was able to display global categories with global products on my main marketplace store – matching on category nicename.

    Although, would still like to see the global product categories as native functionality in MarketPress.

    Thanks again!

  • MoeJoe
    • Flash Drive

    Hi all,

    I really need some help and clarification for anyone who is willing to help.

    I uploaded the two files style-wp-admin.php and wp-admin.css to my mu-plugins folder, but when I created a new store the “+Add New Product Category” link is still there. The plugin is however showing up in the must use section, so I can only assume that wp is using it.

    Anyone have any ideas on troubleshooting why it isn’t going away.

    Another question I have is I noticed at the top of the users admin page there is a “Categories” link in the “Store Admin” menu at top. If you go into that “Categories” menu link it goes into another page which has another “Add New” link. How did you get rid of it? Is that what Step 4 is referring to above.

    Next Question –>

    We simply changed the permissions for the Product Categories to Super Admin and moved it to a private menu we have for Super Admins only

    Here is what I did-

    1. Installed Admin Menu Editor plugin in the normal plugin folder not the mu-plugins folder (alex’s post above somewhat confused me)

    I installed admin menu editor. It works really well.

    Did you make sure to install it under /wp-content/mu-plugins/?

    Also need to move admin-menu-editor-mu.php from admin-menu-editor/includes to /wp-content/mu-plugins/

    2. I then networked activated it.

    3. Went into the menu editors settings (inside my blog template), went into “products menu” and then into the “products categories” and set the “Required capability” to “super-admin”

    4. I then created a new menu in here called “private product categories” and moved the “product categories” to it. Is that what Saunt Valerian is referring to

    moved it to a private menu we have for Super Admins only

    If not what is he referring to and how do you setup a private menu for super admins.

    Hope someone out there can help me work through this as I am pretty new at wp.

    One other note is that I have this installation locally until I have all the bugs worked out. I don’t think that having it locally is the problem, because everything else on the site works, except for this.

    Thanks all

  • MoeJoe
    • Flash Drive

    One other plugin I have on the site which may or may not make any difference at all is the TT Mp-FrontEnd Plugin.

    This has been driving me crazy because I believe I have done everything correct.

    Hope to hear from someone soon.

  • nickrosener
    • Flash Drive

    The idea is like EBay (for anyone in this conversation that is unclear about it):

    Categories the super admin makes, that regular admins can only use for their site. Products in these categories appear on the reg. admin sites, and on the super admin site (main site) as global categories, listing all products, in those categories, network wide.

    I THINK, that will following the steps that Saunt Valerian would allow for ONLY those categories to be used for reg. admins. Therefore, calling global categories on the main site, should again list ONLY those categories. The last piece is, hopefully on the super admin site (main site) reg admin products will be listed in the global categories, which I THINK that is how it works.. I will find out shortly..

    Just wanted to be clear..

  • EspaceRA
    • Design Lord, Child of Thor

    Hi !

    Thank you for this tutorial ! I tested this and I have some questions :

    How can we do to push sub-categories on the network ? Is it possible ?

    I’m not sure to understand with my bad English and it’s don’t work on my website :

    Did the global products list widget work with this tutorial ?

  • hydrastudio
    • Site Builder, Child of Zeus

    Hi all,

    Sorry to reopen a old thread but does this still work in 3.8.1? Does this solve this scenario:

    1) Network Admin has control over each sites categories – can be done by using blog templates plugin and hiding the ‘categories’ menu option. Fine and dandy.

    2) On the main site, I want to show these categories with ALL items from the network sites that are in those categories.

    I can get it to have the categories in place when new sites are create (part 1) but how do I get that category to show all products from across the network (part 2)? Am I missing something with this?

    ARGH!!! It’s so frustrating that something like this isn’t in the MS core or there isn’t a plugin for it.

    Thanks

    Gavin.

  • DavidM
    • DEV MAN’s Mascot

    Hi Gavin,

    Sorry I missed this til now. It’s been quite a while since this initial posting so I’m not back up to speed on what’s all needed, but will have a look.

    Given what you’re asking, would the global product listing shortcodes already in MarketPress work for your product listing?

    Or as should already be available, the marketplace category slug?

    /marketplace/category/

    Were you looking for something more specific?

    Thanks,

    David

  • hydrastudio
    • Site Builder, Child of Zeus

    Hi DavidM,

    Sorry for the delay in responding, I never got a notice of your post (or did and didn’t notice it which is more likely!)

    I will have to have another go. I can’t remember if we were using the marketplace category slug. Been a while and I shelved it as i couldn’t get it to work.

    I will be back when I have something,

    Thanks

    Gavin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.