Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save travislima/0e9757a91b5ce0f812dd3575abb86da2 to your computer and use it in GitHub Desktop.
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
<?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 );
@laurenhagan0306
Copy link

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment