Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ideadude
Last active October 17, 2018 09:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ideadude/5c7ed35a50087178a47d92b192933614 to your computer and use it in GitHub Desktop.
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
<?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