Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created June 17, 2020 11:38
Show Gist options
  • Save andrewlimaza/40c8f603d1907f55b109ad7b752140ae to your computer and use it in GitHub Desktop.
Save andrewlimaza/40c8f603d1907f55b109ad7b752140ae to your computer and use it in GitHub Desktop.
Show the membership level name on single product view WooCommerce. [Paid Memberships Pro]
<?php
/**
* Show membership product name for a WooCommerce product if assigned to a level.
* Add this code to your site by following this example: https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_show_level_name_woo_product() {
global $product;
$level_id = get_post_meta( $product->get_id(), '_membership_product_level', true );
if ( empty( $level_id ) ) {
return;
}
$level = pmpro_getLevel( $level_id );
if ( isset( $level->name ) ) {
echo '<p>Membership Level: ' . $level->name . '</p>';
}
}
add_action( 'woocommerce_product_meta_end', 'my_pmpro_show_level_name_woo_product' );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Show the Membership Level Name for a Membership Product Sold via WooCommerce" at Paid Memberships Pro here: https://www.paidmembershipspro.com/level-name-single-membership-product-woocommerce/

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