Created
January 8, 2020 08:55
-
-
Save andrewlimaza/6384264008f01236ff2096bb1dd7fc5b to your computer and use it in GitHub Desktop.
Give members a free WooCommerce downloadable Product [Paid Memberships Pro Snippet]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Give certain downloadable products to Paid Memberships Pro members for free. | |
* Adjust the code to your needs and to match your WooCommerce Product IDs and Membership Level IDs. | |
* Follow this guide to add the code to your WordPress website - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function free_download_product_for_members( $discount_price, $level_id, $original_price, $product ) { | |
$allowed_free_products = array( 58, 59, 100, 300, 501); // Adjust this with the WooCommerce Product ID's that are allowed to be discounted. | |
$allowed_levels = array( '1', '2' ); //Adjust this for membership levels that qualify for the discount. | |
// Check to see if product is in allowed product array. | |
if ( ! in_array( $product->get_id(), $allowed_free_products ) ) { | |
return $discount_price; | |
} | |
// If the product is set to downloadable and the user belongs to the right membership level, discount the price to free. | |
if ( $product->is_downloadable( 'yes' ) && pmpro_hasMembershipLevel( $allowed_levels ) ) { | |
$discount_price = 0; | |
} | |
return $discount_price; | |
} | |
add_filter( 'pmprowoo_get_membership_price', 'free_download_product_for_members', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment