Skip to main content

Is there an out-of-the-box way to restrict purchases by certain user roles?

I wanted to check if FluentCart already supports (or plans to support) role-based purchase restrictions β€” for example, preventing certain roles like administrator from buying specific products or all products.

I couldn’t find a built-in setting or filter for this, so I implemented it using FluentCart hooks and the Cart API.

This is the approach I’m currently using β€” just want to confirm:

  1. Whether there’s an official/native way to do this
  2. If not, whether this approach is considered correct/safe
  3. And if role-based purchase restriction is something that might be added natively in the future

define('BLOCKED_PURCHASE_ROLES', ['administrator']);
define('MEMBERSHIP_PRODUCT_IDS', [1, 2, 3]);

add_action('fluent_cart/cart/item_added', 'block_roles_from_purchasing', 10, 1);
add_action('fluent_cart/cart/cart_completed', 'block_roles_from_purchasing', 10, 1);

function block_roles_from_purchasing($data) {

if (!is_user_logged_in() || empty($data['cart'])) {
    return;
}

$user = wp_get_current_user();

if (!array_intersect((array) $user->roles, BLOCKED_PURCHASE_ROLES)) {
    return;
}

$cart = $data['cart'];

foreach ($cart->getItems() as $item) {
    $product_id = (int) $item['product_id'];

    if (in_array($product_id, MEMBERSHIP_PRODUCT_IDS, true)) {
        $cart->removeItem($product_id, [], true);
    }
}

}

Kyle Dee

This is effectively the same method I am using except I am doing it by FluentCRM tags instead of roles.

Rupesh Padhi

This approach may work only with the standard cart flow. But it won't work with Direct Checkout.

Direct checkout bypasses the cart lifecycle, so hooks like fluent_cart/cart/item_added and cart_completed don’t fire.

At the moment, FluentCart docs don’t expose any documented hooks or native options to enforce role-based purchase restrictions during direct checkout.

Do you have any solution Shahjahan JewelΒ ?

Kyle Dee

Rupesh PadhiΒ I'm thinking today's new release with ghost products may be useful for this

Rupesh Padhi

Kyle Dee Maybe. Ghost products are new to me. I haven’t tested them yet with Direct Checkout. If they change the checkout flow or expose hooks, it could work. Any docs or example?