Forked from messica/my_woocommerce_get_price_html.php
Created
October 28, 2019 11:48
-
-
Save kimcoleman/51e0e9b3973e7fbbb72f5a2ebd8f8b97 to your computer and use it in GitHub Desktop.
Display membership pricing along with regular pricing.
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 | |
// 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