Created
June 17, 2020 11:38
-
-
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]
This file contains 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 | |
/** | |
* 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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/