跳到内容

Coupons Role Restriction for WooCommerce

v1.1.4

runthings.dev · 2024年7月15日 上架

Restrict the usage of WooCommerce coupons based on user roles.

正在使用
60+
评分
暂无
累计下载
2,655
最近更新
2026年11月16日
需要 WordPress 6.4+已测试到 7.1.5PHP 7.4+

贡献者

截图

Coupon settings page with role restriction fields.
Coupon settings page with role restriction fields.
Coupon role selection field.
Coupon role selection field.
Example denied coupon usage due to invalid role.
Example denied coupon usage due to invalid role.

This plugin allows you to restrict the usage of WooCommerce coupons based on user roles, including guest users.

You can specify which roles (including guests) are allowed or excluded from using a coupon, providing more control over your discount strategies.

Features

  • Restrict coupon usage based on user roles.
  • Option to specify both allowed and excluded roles.
  • Support for guest users with a “Customer Is A Guest” pseudo-role.
  • Customize the error message via a filter.

Filters

runthings_wc_coupons_role_restrict_error_message

This filter allows customization of the error message shown when a coupon is not valid for the user’s account type.

For detailed documentation and advanced examples, see the full documentation on GitHub.

Parameters:

  1. $message (string): The default error message, e.g., "Sorry, this coupon is not valid for your account type.".
  2. $context (array): Additional context for the error, including the coupon, user roles, and guest status.

$context object format:

The $context array contains the following keys:
– coupon (WC_Coupon): The coupon object being validated.
– is_guest (bool): Whether the current user is a guest (not logged in).
– user (WP_User): The current user object. For guests, this will be an empty user object.
– allowed_roles (array): Roles explicitly allowed to use the coupon, in the format [role_id => role_name].
– excluded_roles (array): Roles explicitly excluded from using the coupon, in the format [role_id => role_name].
– effective_allowed_roles (array): The final calculated roles allowed to use the coupon, after considering exclusions, in the format [role_id => role_name]. This is the set of roles that can use the coupon.

License

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, see http://www.gnu.org/licenses/gpl-3.0.html.

Icon – Discount by Gregor Cresnar, from Noun Project, https://thenounproject.com/browse/icons/term/discount/ (CC BY 3.0)

Icon – restriction by Puspito, from Noun Project, https://thenounproject.com/browse/icons/term/restriction/ (CC BY 3.0)

Plums

按场景查找 WordPress 插件。安装量、评分和兼容版本来自官方目录。

导航

说明

WordPress 是 WordPress Foundation 的商标。本站与 WordPress Foundation、Automattic 没有隶属关系。这里不托管插件文件,下载和安装以 WordPress.org 上的页面为准。

© 2026 Plums