Supporting Wholesale Users

There are a few different ways to support wholesale users with FoxyShop. The simplest is to have a separate batch of products that your wholesale users can order. In order to support this, I’ve put together an add-on plugin for FoxyShop which you can download here. Just download this file and put it in wp-content/plugins. Then you can can go into WordPress and enable it.

This plugin requires the Advanced Custom Fields plugin (the free version is fine). Once this is installed, you’ll be able to edit your products and categories and set them with access restrictions. Then you can create your wholesale users and assign them to the Wholesale role.

You may also want to consider installing the Peter’s Login Redirect plugin to control where your wholesale visitors are sent after login.

I recommend putting this in your single product template:

//Check Access
if (get_field("access_restriction") == "wholesale" && !check_user_role(array("wholesale", "administrator"))) {
die("Please login before accessing this product.");
}
$product_categories = wp_get_post_terms($product['id'], 'foxyshop_categories', array("fields" => "all"));
if ($product_categories && !is_user_logged_in()) {
foreach ($product_categories as $term) {
$access_restriction = get_field("access", $term->taxonomy . "_" . $term->term_id);
if ($access_restriction == "wholesale") {
die("Please login before accessing this product.");
}
}
}

And this in your in your single category template (around line 25):

//Check Wholesale Access Restriction
$access_restriction = get_field("access", $term->taxonomy . "_" . $term->term_id);
if ($access_restriction == "wholesale" && !is_user_logged_in()) {
die("Please login before accessing this section.");
}

Adding these bits of code will further secure the wholesale categories and products from prying eyes.

Leave a Reply

Your email address will not be published. Required fields are marked *