{"id":404635,"date":"2024-07-15T08:00:00","date_gmt":"2024-07-15T08:00:00","guid":{"rendered":"https:\/\/www.weixiaoduo.com\/plugins\/runthings-wc-coupons-role-restrict\/"},"modified":"2025-06-25T05:13:00","modified_gmt":"2025-06-25T05:13:00","slug":"runthings-wc-coupons-role-restrict","status":"publish","type":"post","link":"https:\/\/www.weixiaoduo.com\/plugins\/runthings-wc-coupons-role-restrict\/","title":{"rendered":"Coupons Role Restriction for WooCommerce"},"content":{"rendered":"<p>This plugin allows you to restrict the usage of WooCommerce coupons based on user roles, including guest users.<\/p>\n<p>You can specify which roles (including guests) are allowed or excluded from using a coupon, providing more control over your discount strategies.<\/p>\n<h4>Features<\/h4>\n<ul>\n<li>Restrict coupon usage based on user roles.<\/li>\n<li>Option to specify both allowed and excluded roles.<\/li>\n<li>Support for guest users with a \u201cCustomer Is A Guest\u201d pseudo-role.<\/li>\n<li>Customize the error message via a filter.<\/li>\n<\/ul>\n<h3>Filters<\/h3>\n<h4>runthings_wc_coupons_role_restrict_error_message<\/h4>\n<p>This filter allows customization of the error message shown when a coupon is not valid for the user\u2019s account type.<\/p>\n<p>For detailed documentation and advanced examples, see the <a href=\"https:\/\/github.com\/runthings-dev\/runthings-wc-coupons-role-restrict#filters\" rel=\"nofollow ugc\">full documentation on GitHub<\/a>.<\/p>\n<p>Parameters:<\/p>\n<ol>\n<li><strong><code>$message<\/code><\/strong> (<code>string<\/code>): The default error message, e.g., <code>\"Sorry, this coupon is not valid for your account type.\"<\/code>.<\/li>\n<li><strong><code>$context<\/code><\/strong> (<code>array<\/code>): Additional context for the error, including the coupon, user roles, and guest status.<\/li>\n<\/ol>\n<p><code>$context<\/code> object format:<\/p>\n<p>The <code>$context<\/code> array contains the following keys:<br \/>\n\u2013 <strong><code>coupon<\/code><\/strong> (<code>WC_Coupon<\/code>): The coupon object being validated.<br \/>\n\u2013 <strong><code>is_guest<\/code><\/strong> (<code>bool<\/code>): Whether the current user is a guest (not logged in).<br \/>\n\u2013 <strong><code>user<\/code><\/strong> (<code>WP_User<\/code>): The current user object. For guests, this will be an empty user object.<br \/>\n\u2013 <strong><code>allowed_roles<\/code><\/strong> (<code>array<\/code>): Roles explicitly allowed to use the coupon, in the format <code>[role_id => role_name]<\/code>.<br \/>\n\u2013 <strong><code>excluded_roles<\/code><\/strong> (<code>array<\/code>): Roles explicitly excluded from using the coupon, in the format <code>[role_id => role_name]<\/code>.<br \/>\n\u2013 <strong><code>effective_allowed_roles<\/code><\/strong> (<code>array<\/code>): The final calculated roles allowed to use the coupon, after considering exclusions, in the format <code>[role_id => role_name]<\/code>. This is the set of roles that can use the coupon.<\/p>\n<h3>License<\/h3>\n<p>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.<\/p>\n<p>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.<\/p>\n<p>You should have received a copy of the GNU General Public License along with this program; if not, see <a href=\"http:\/\/www.gnu.org\/licenses\/gpl-3.0.html\" rel=\"nofollow ugc\">http:\/\/www.gnu.org\/licenses\/gpl-3.0.html<\/a>.<\/p>\n<p>Icon \u2013 Discount by Gregor Cresnar, from Noun Project, https:\/\/thenounproject.com\/browse\/icons\/term\/discount\/ (CC BY 3.0)<\/p>\n<p>Icon \u2013 restriction by Puspito, from Noun Project, https:\/\/thenounproject.com\/browse\/icons\/term\/restriction\/ (CC BY 3.0)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Restrict the usage of WooCommerce coupons based on user roles.<\/p>\n","protected":false},"author":65,"featured_media":404636,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Coupons Role Restriction for WooCommerce - \u8587\u6653\u6735\u63d2\u4ef6\u76ee\u5f55","description":"Restrict the usage of WooCommerce coupons based on user roles."},"footnotes":""},"categories":[1],"tags":[1883,4375,56226,11370,42],"class_list":["post-404635","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-coupons","tag-discount","tag-role-restriction","tag-user-roles","tag-woocommerce"],"_links":{"self":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/404635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/comments?post=404635"}],"version-history":[{"count":0,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/404635\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media\/404636"}],"wp:attachment":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media?parent=404635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/categories?post=404635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/tags?post=404635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}