Forked from andrewlimaza/my_pmprowoo_get_membership_price.php
Last active
December 20, 2023 03:23
-
-
Save travislima/0e9757a91b5ce0f812dd3575abb86da2 to your computer and use it in GitHub Desktop.
Use the pmprowoo_get_membership_price filter to set prices for variable products with Paid Memberships Pro and WooCommerce
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 | |
/** | |
* Use the pmprowoo_get_membership_price filter to set prices for variable products. | |
* Update the $membership_prices array. | |
* Each item in that array should have a key equal to the membership level id, | |
* and a value equal to an array of the form array( {variable_product_id} => {member_price} ) | |
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmprowoo_get_membership_price( $discount_price, $level_id, $original_price, $product ) { | |
// Setup your arrays of product ids to membership prices. | |
$membership_prices = array( | |
'1' => array( //-level 1 prices- | |
'100' => '10.00', //--product #100 price for level 1 | |
'101' => '15.00', //--product #101 price for level 1 | |
'102' => '20.00', //--product #101 price for level 1 | |
), | |
'2' => array( //-level 2 prices- | |
'100' => '5.00', //--product #100 price for level 2 | |
'101' => '10.00', //--product #101 price for level 2 | |
'102' => '15.00', //--product #101 price for level 2 | |
), | |
); | |
// Find the level_id, product combo to get the price. | |
if( isset( $membership_prices[$level_id] ) && | |
isset( $membership_prices[$level_id][$product->get_id()] ) ) { | |
$discount_price = $membership_prices[$level_id][$product->get_id()]; | |
} | |
return $discount_price; | |
} | |
add_filter( 'pmprowoo_get_membership_price', 'my_pmprowoo_get_membership_price', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Set WooCommerce Variable Product Prices Per Membership Level" at Paid Memberships Pro here: https://www.paidmembershipspro.com/set-woocommerce-variable-product-prices-per-membership-level/