Skip to main content

Describe each tier on a membership-plugin show’s subscribe cards

Premium Intermediate

On a show using MemberPress, WooCommerce Subscriptions, Paid Memberships Pro or Restrict Content Pro, [benecaster_subscribe] prints each tier’s name, the plugin’s price and a Subscribe button to the plugin’s signup page — but no description, because Benecaster’s tier mapping holds none. This example pulls one from the membership plugin’s own level, so the description is written in one place: here, each MemberPress membership’s excerpt.

Do not print a price or a button in this hook. Benecaster prints both, so yours would be a second one.

Two levels mapped to one tier render two cards with the same $slug, but each card gets its own $level_id, so each gets its own membership’s excerpt. Register with 10, 4 to receive the level and plugin arguments.

For another plugin, branch on $plugin_slug (woo-subscriptions, paid-memberships, restrict-content) and read that plugin’s description for $level_id, a WooCommerce product’s short description, for example.

The benecaster-subscribe__description class picks up the description styling Benecaster’s subscribe stylesheet already has. It is one of the card classes listed on the subscribe shortcode’s page.

A show on Benecaster’s built-in membership never fires this hook; its tier descriptions are edited under Memberships → Tiers.

Code

<?php
// MemberPress: show each membership's excerpt under its card.
add_action( 'benecaster_subscribe_tier_content', function ( string $slug, int $show_id, string $level_id = '', string $plugin_slug = '' ): void {
    if ( 'memberpress' !== $plugin_slug || '' === $level_id ) {
        return; // A manually managed tier, or another plugin's level.
    }
    $excerpt = get_the_excerpt( (int) $level_id );
    if ( '' !== $excerpt ) {
        echo '<p class="benecaster-subscribe__description">' . esc_html( $excerpt ) . '</p>';
    }
}, 10, 4 );

View on GitHub →

Hooks Used

Need this built rather than just documented? See our services →