Skip to content

Instantly share code, notes, and snippets.

@messica
Created February 1, 2017 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save messica/d1654e478748ed0ada2cac02be75ed46 to your computer and use it in GitHub Desktop.
Save messica/d1654e478748ed0ada2cac02be75ed46 to your computer and use it in GitHub Desktop.
Display membership pricing along with regular pricing.
<?php
// Display membership pricing along with regular pricing.
function my_woocommerce_get_price_html($price, $product) {
// Get all levels.
$all_levels = pmpro_getAllLevels(true, true);
// Get original price.
$reg_price = wc_price($product->get_regular_price());
// Find all membership prices for this product.
$member_prices = array();
foreach($all_levels as $level) {
$member_price = get_post_meta($product->id, "_level_{$level->id}_price", true);
if(!empty($member_price) || $member_price === '0')
$member_prices[$level->id] = $member_price;
}
// Build list.
$list = "<ul><li>Regular Price: {$reg_price}</li>";
foreach($member_prices as $level_id => $price) {
$wc_price = wc_price($price);
$list .= "<li>{$all_levels[$level_id]->name} Price: {$wc_price}</li>";
}
$list .= "</ul>";
return $list;
}
add_filter('woocommerce_get_price_html', 'my_woocommerce_get_price_html', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment