Does your membership site also sell physical or digital products? If your site also features a WooCommerce store, there are some pretty cool things you can do to offer shopping incentives for your premium members.

With our WooCommerce Integration, membership sites can set a shop-wide or per-product discount for users with an active membership level. But what if you want to make a certain category of products completely free for your members? In this code recipe, we show you how to do just that. 

Instead of manually editing all products to set the member price, this recipe handles the update in bulk. Use this code to set all products in certain categories to free for anyone logged in with an active membership level.

Make All WooCommerce Products in Specific Category Free for Members Code Recipe Banner Image

About the Code Recipe

This recipe demonstrates how to use the pmprowoo_get_membership_price filter in the WooCommerce Integration Add On to adjust the price of products for members-only. 

When an active member is logged in, this code recipe will show the items in a specified category as free.

Ebook sample WooCommerce product page free for signed in member

When a non-member views the item or the user is not logged in, the recipe will show the regular product price details.

Single product in WooCommerce showing price of product for non-member

You can use this code as an example for your own site needs by customizing the code for similar concepts like:

  1. Give members a better discount or percent off based on the product category.
  2. Set one or more product categories to free for members.
  3. Check a specific membership level ID before applying the free or reduced price discount on the product category.
  4. Adjust the price for a product category temporarily, such as during a bonus sale period, for members.

This code also shows the free or regular product price in your primary shop page and product category archives.

Product archive showing category of products at regular price for non-members.
Product archive showing category of products at regular price for non-members.
Product archive showing category of products free for active members.
Product archive showing category of products free for active members.

The Code Recipe (PHP)

Adding the Recipe to Your Website

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.

Update the $free_product_cats array on line 29 to your specific product category slugs.

Optionally uncomment lines 24 to 26 to check for a specific membership level ID. Without that line, all users logged in to an account with an active membership or with a membership product in the cart will receive the discounted price.

Free Course: Membership Site Development—The Basics

Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.

Featured Image for Membership Site Development Course: The Basics
Was this article helpful?
YesNo