Our WooCommerce Integration allows you to offer members-only product discounts with WooCommerce, either as a global percentage off or per-product. WooCommerce itself also lets you set a product to be ‘on sale’. This recipe is for sites that offer a global discount for members and want to remove the member discount for products on sale.
Use this drop-in code recipe to will automatically exclude any WooCommerce product with a sale price from receiving the members-only discount.
Table of contents
About the Code Recipe
This code snippet customizes the application of discounts to products when using PMPro’s WooCommerce Add On.
The goal of this recipe is to remove the member discount for products on sale, ensuring that only full price products receive an additional members-only discount.
- If the product is on sale, the member will pay the sale price.
- If the product is not on sale, the member will receive their normal discount on the product’s regular price.
Here’s a breakdown of how it works:
- The code hooks into the
pmprowoo_get_membership_price
filter in our Add On, which determines the membership pricing for products. - The function uses the
$product->get_sale_price()
method in WooCommerce to get the sale price of the product. It also uses the$product->is_on_sale()
method to determine if the product is currently on sale.- If the product is not on sale, the function allows the regular membership discount to be applied by returning the
$discount_price
. - If the product is on sale, the function ensures that no additional discount is applied, returning the sale price (
$sale_price
).
- If the product is not on sale, the function allows the regular membership discount to be applied by returning the
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.
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.