Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use the pmprowoo_get_membership_price filter to set prices for variable products with Paid Memberships Pro and WooCommerce
<?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
You can’t perform that action at this time.