How to Control Who Can Access WooCommerce Coupons

A PublishPress user asked an interesting question: “We want to give our users access to the coupons they create. We can use PublishPress Capabilities to give them access to the coupons are, but unfortunately they can see all the coupons created, including those created by other users”.

Yes, this possible with PublishPress plugins.

This is possible because WooCommerce stores coupons as a regular WordPress post type. So plugins that can control WordPress posts can also be used to control WooCommerce coupons.

WooCommerce coupons are stored in the wp_posts table and the post_type is shop_coupon. And all of the associated data for coupons is stored in the wp_postmeta table. This image shows a coupon stored in the wp_poststable:

Using the PublishPress Capabilities plugin, you can control many different permissions for coupons.

Permissions for WooCommerce Coupons #

After installing the plugin, go to “Capabilities” in your WordPress admin menu. You can control Edit / Create / Delete / Read permissions for your coupons, using the settings in the image below.

Viewing Other People's WooCommerce Coupons #

This is the answer to the original question from the PublishPress user. In a multi-vendor setup, you can control who can see coupons created by other users.

  • Install the PublishPress Permissions plugin.
  • Go to Permissions > Settings > Core.
  • Check the box for “Coupons” under “Filtered Post Types”.

Now when your site's vendors go to the “Coupons” screen, they will only be able to see coupons that they create.

Also, inside each coupon you will see two new boxes:

  • Permissions: Read this Coupon.
  • Permissions: Edit this Coupon.

These boxes allow you to set very specific permissions for each role, group or specific user:

Show the Author on the Coupon Screen #

It is possible to visibly show the author for each coupon. This is another way to grant editing permission to coupons because authors can access the content they have created.

Add this code to your theme's functions.php file:

function add_author_support_to_posts() {
   add_post_type_support( 'shop_coupon', 'author' ); 
add_action( 'init', 'add_author_support_to_posts' );

Now inside each coupon, you will see an “Authors” box:

Professional publishing plugins for WordPress! Get PublishPress