Last active
October 17, 2018 09:48
-
-
Save ideadude/5c7ed35a50087178a47d92b192933614 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 hidden or 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 into a custom plugin. | |
*/ | |
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