WooCommerce Memberships Frontend Hook Reference

In this article

For Developers: Frontend Hook Reference

This document covers all frontend-specific hooks in WooCommerce Memberships. You can also view the document on admin-specific hooks.

WooCommerce Memberships is extremely extensible and offers ample actions and filters for developers to customize it as needed. If a hook doesn’t exist where you think it should, please submit a ticket so we can consider its addition.

This hook reference includes some of the actions and filters developers may find useful while customizing the plugin, but is not an exhaustive reference of all plugin hooks. Inline docs include parameters and returned values for more detail — the appropriate file for each hook is listed so you can refer to it.

Please note that this document is a developer reference provided as a courtesy, as our support policy does not include customizations.
This reference lists helpful filters / actions and is meant to be a directory. Please see the plugin’s inline documentation for additional details on parameters, returned values, and usage.

 

Filters: Member Messages

All filters for member messages are located in: /includes/frontend/class-wc-memberships-frontend.php

wc_memberships_user_membership_cancelled_notice

@since

 

1.0.0

 

@param

 

string $notice

 

@return

 

string – updated notice

Filter the user cancelled membership message on frontend — defaults to, “Your membership was cancelled.”

wc_memberships_member_login_message

@since

 

1.3.8

 

@param

 

string $message The message text

 

@return

 

string – the updated message

Filter the member login notice message. This can be configured under settings as well, but we recommend using the default message and filtering as needed, as by default this message responds to the number of discounted items in the cart.

 

Filters: Restriction Messages

All frontend filters are included in: /includes/frontend/class-wc-memberships-frontend.php

wc_memberships_the_restricted_content

@since

 

1.6.0

 

@param

 

string $content HTML content displayed for the post

 

@param

 

bool $restricted Whether the content is restricted

 

@param

 

string $message The restriction message applied, could be empty string

 

@param

 

WP_Post $post The post being restricted

 

@return

 

string – the updated restricted content HTML

If you wanted to remove a restriction notice completely, you could use this filter to modify the message HTML or delete it. This example snippet shows its use for modifying the restricted content, so you could return the content without the restriction message, or modify the message and return the content as desired.

wc_memberships_product_viewing_restricted_message

@since

 

1.0.0

 

@param

 

string $message The restriction message

 

@param

 

int $product_id ID of the product being restricted

 

@param

 

array $products Array of product IDs that grant access to this product

 

@return

 

string – the updated restriction message

Filters the product viewing restricted message.

wc_memberships_product_purchasing_restricted_message

@since

 

1.0.0

 

@param

 

string $message The restriction message

 

@param

 

int $product_id ID of the product being restricted

 

@param

 

array $products Array of product IDs that grant access to this product

 

@return

 

string – the updated restriction message

Filters the product purchasing restricted message.

wc_memberships_content_restricted_message

@since

 

1.0.0

 

@param

 

string $message The restriction message

 

@param

 

int $post_id ID of the product being restricted

 

@param

 

array $products Array of product IDs that grant access to this product

 

@return

 

string – the updated restriction message

Filters the content restricted message.

wc_memberships_get_content_delayed_message

@since

 

1.3.1

 

@param

 

string $message Delayed content message

 

@param

 

int $post_id Post ID that the message applies to

 

@param

 

string $access_time Access time timestamp

 

@return

 

string – the updated restriction message

Filters the content delayed message.

Example to show a custom delayed message for the “project” post type:

 

<?php // only copy this line if needed
/**
 * Change the "content delayed" message displayed to members who will have access, but not yet
 * Example: change the delayed content message for the "Projects" post type
 *
 * @param string $message the message html
 * @param string[] $args {
 *      @type string $context whether the message appears in the context of a notice or elsewhere
 *      @type WP_Post $post the post object
 *      @type int $post_id the ID of the restricted post
 *      @type int $access_time the user access timestamp
 *      @type int[] $products the product IDs that grant access
 *      @type string $rule_type the related rule type
 *      @type string|string[] $classes optional message CSS classes
 * }
 * @return string $message the updated message text
 */
function sv_wc_memberships_change_content_delayed_message( $message, $args ) {

        // only change the delayed message if a project is being viewed
        // {date} will be replaced automatically after this filter with access date
        if ( 'project' === get_post_type( $args['post_id'] ) ) {
                $message = 'This project is part of your membership, but not yet! You will gain access on {date}';
        }

        return $message;
}
add_filter( 'wc_memberships_content_delayed_message', 'sv_wc_memberships_change_content_delayed_message', 10, 2 );
woocommerce-memberships/frontend/change-content-delayed-access-message.php

 

wc_memberships_product_taxonomy_viewing_restricted_message

@since

 

1.4.0

 

@param

 

string $message The restriction message

 

@param

 

string $taxonomy Product taxonomy

 

@param

 

int $term_id Product taxonomy term id

 

@param

 

array $products Array of product IDs that grant access to products taxonomy

 

@return

 

string – the updated restriction message

Filters the product category viewing restricted message. Defaults to, “This product category can only be viewed by members. To view this category, sign up by purchasing {products}, or log in if you are a member.” If no product purchases can grant access to the category, defaults to, “This product category can only be viewed by members.”

wc_memberships_product_term_viewing_delayed_message

@since

 

1.4.0

 

@param

 

string $message The delayed access message

 

@param

 

string $taxonomy Product taxonomy

 

@param

 

int $term_id Product taxonomy term id

 

@return

 

string – the updated restriction message

Filter the product term viewing delayed access message. Defaults to, “This product category is part of your membership, but not yet! You will gain access on {date}.”

wc_memberships_member_discount_message

@since

 

1.0.0

 

@param

 

string $message The discount message

 

@param

 

int $product_id ID of the product that has member discounts

 

@param

 

array $products Array of product IDs that grant access to this product

 

@return

 

string – the updated discount message

Filters the member discount message shown to non-members or non-logged in users.

 

Filters: Member Discounts

wc_memberships_member_prices_use_discount_format

@since

 

1.3.0

 

@param

 

bool $use_discount_format Defaults to true

located in: /includes/class-wc-memberships-member-discounts.php

Controls whether or not member prices should use discount format when displayed. If returned false, discounted prices will be shown without the original price. Defaults to true.

wc_memberships_member_prices_display_sale_price

@since

 

1.3.0

 

@param

 

bool $display_sale_price Defaults to false

located in: /includes/class-wc-memberships-member-discounts.php

Controls whether or not member prices should display sale prices as well. If returned true, the original price, sale price, and member price will be shown.

Default: $nonmember price $member price
Returned True: $original price $sale price $member price

Defaults to false — only shows sale price [if set] and member price, or original price and member price.

wc_memberships_member_discount_badge

@since

 

1.0.0

 

@param

 

string $badge_html the member discount badge HTML

 

@param

 

WP_Post $post Post object

 

@param

 

WC_Product $product Product object

 

@return

 

string – updated badge HTML

located in: /templates/loop/member-discount-badge.php

Filters the Member Discount badge HTML.

 

Filters: My Memberships

wc_memberships_my_memberships_title

@since

 

1.5.0

 

@param

 

string $title My Memberships table title

 

@return

 

string – updated title

located in: /templates/myaccount/my-memberships.php

Filters the title of the My Memberships table. Defaults to “My Memberships”.

wc_memberships_my_memberships_column_names

@since

 

1.4.0

 

@param

 

array $my_memberships_columns Associative array of column ids and names

 

@param

 

int $user_id ID of logged in user

 

@return

 

array – updated array of columns

located in: /templates/myaccount/my-memberships.php

Filters the My Memberships table columns in My Account page. Example: remove “end date” column:

 

<?php // only copy this line if needed
/**
 * Remove the "End Date" column from the My Memberships table
 *
 * @param array $columns the columns in the "My Memberships" table
 * @return array $columns the updated array of columns
 */
function sv_wc_memberships_remove_end_date_column( $columns ) {

        unset( $columns['membership-end-date'] );
        return $columns;
}
add_filter( 'wc_memberships_my_memberships_column_names', 'sv_wc_memberships_remove_end_date_column' );
woocommerce-memberships/frontend/remove-my-memberships-end-date-column.php

 

wc_memberships_get_renew_membership_url

@since

 

1.0.0

 

@param

 

string $url renewal URL

 

@param

 

WC_Memberships_User_Membership $user_membership

 

@return

 

string – updated URL

located in: /includes/class-wc-memberships-user-membership.php

Filters the renewal URL for a membership. Helpful if you want to change the renewal URL / button to “upgrade” a membership.

Example: Renew trial plan by purchasing an upgrade.

wc_memberships_get_cancel_membership_url

@since

 

1.0.0

 

@param

 

string $url cancellation URL

 

@param

 

WC_Memberships_User_Membership $user_membership

 

@return

 

string – updated URL

located in: /includes/class-wc-memberships-user-membership.php

Filters the cancel URL for a membership. Not needed for memberships purchased via subscription, as the button is hidden.

 

Filters: Member Area

We have an overview of customizing the member area and adding custom sections.

wc_membership_plan_members_area_sections

@since

 

1.4.0

 

@param

 

array $member_area_sections Associative array with member area id and label of each section

 

@param

 

int|string $membership_plan Optional, the current membership plan, might be empty

 

@return

 

array – updated array of sections

located in: /includes/wc-memberships-membership-plan-functions.php

Filters the available choices for the members area sections of a membership plan.

Example: Rename the section links:

 

<?php // only copy this line if needed
/**
 * Rename the section links for the "Member Area"
 * Can rename any section links using the section ID
 *
 * @param array $sections the array of section link IDs and text
 * @return array $sections the updated array of section links
 */
function sv_wc_memberships_rename_member_area_sections( $sections ) {

        $sections['my-membership-content']   = __( 'Club Articles', 'my-text-domain' );
        $sections['my-membership-products']  = __( 'Club Products', 'my-text-domain' );
        $sections['my-membership-discounts'] = __( 'Exclusive Discounts', 'my-text-domain' );
        $sections['my-membership-notes']     = __( 'Notes from MySite', 'my-text-domain' );

        return $sections;
}
add_filter( 'wc_membership_plan_members_area_sections', 'sv_wc_memberships_rename_member_area_sections' );
woocommerce-memberships/frontend/member-area/rename-member-area-section-links.php

 

wc_memberships_members_area_{$section}_actions

@since

 

1.4.0

 

@param

 

array $default_actions Associative array of actions

 

@param

 

WC_Memberships_User_Membership $user_membership User Membership object

 

@param

 

WC_Product|WP_Post|object $object Current object where the action is run (optional)

 

@return

 

array – updated array of actions

located in: /includes/wc-memberships-template-functions.php

Filter membership actions on My Account and Members Area pages. The $section is the member area section, e.g., ‘my-membership’, ‘my-membership-content’, etc.

Example: Remove “Cancel” button.

My Membership Content

All hooks for the “My Content” section of the Member Area are located in the template file: /templates/myaccount/my-membership-content.php

wc_memberships_members_area_my_membership_content_title

@since

 

1.4.0

 

@param

 

string $title the section title

 

@return

 

string – the updated title

Filters the heading for the “My Content” section.

wc_memberships_members_area_my_membership_content_column_names

@since

 

1.4.0

 

@param

 

array $columns Associative array of column ids and names

 

@param

 

int $user_id ID of logged in user

 

@return

 

array – updated array of columns

Filters the columns in the “My Content” section. If adding a column, be sure to also fill that column with content using the

wc_memberships_members_area_my_membership_content_column_{$column_id}

action. Example to add an “Author” column:

 

<?php // only copy this line if needed
/**
 * Add an "Author" column to the "My Content" table in the members area
 *
 * @param array $columns the columsn in the "My Content" table
 * @return array $columns the updated array of columns
 */
function sv_wc_memberships_my_content_table_add_column( $columns ) {

        $new_columns = array();

        foreach ( $columns as $column_id => $column_name ) {

                $new_columns[ $column_id ] = $column_name;

                // insert our new "Author" column after the "Title" column
                if ( 'membership-content-title' === $column_id ) {
                        $new_columns['membership-content-author'] = __( 'Author', 'your-textdomain' );
                }
        }

        return $new_columns;
}
add_filter( 'wc_memberships_members_area_my_membership_content_column_names', 'sv_wc_memberships_my_content_table_add_column', 11 );
/**
 * Fills the "Author" column with the post author
 *
 * @param WP_Post $post the post object used for the row's display
 */
function sv_wc_memberships_my_content_table_add_column_content( $post ) {

        $author = get_user_by( 'ID', $post->post_author );
        echo $author->display_name;
}
add_action( 'wc_memberships_members_area_my_membership_content_column_membership-content-author', 'sv_wc_memberships_my_content_table_add_column_content' );
woocommerce-memberships/frontend/member-area/add-author-column-to-my-content.php

 

You could also remove columns: example to remove “Type” column

My Membership Products

All hooks for the “My Products” section of the Member Area are located in the template file: /templates/myaccount/my-membership-products.php

wc_memberships_members_area_my_membership_products_title

@since

 

1.4.0

 

@param

 

string $title the section title

 

@return

 

string – the updated title

Filters the heading for the “My Products” section.

wc_memberships_members_area_my_membership_products_column_names

@since

 

1.4.0

 

@param

 

array $columns Associative array of column ids and names

 

@param

 

int $user_id ID of logged in user

 

@return

 

array – updated array of columns

Filters the columns in the “My Products” section. If adding a column, be sure to also fill that column with content using the

wc_memberships_members_area_my_membership_products_column_{$column_id}

action.

My Membership Discounts

All hooks for the “My Discounts” section of the Member Area are located in the template file: /templates/myaccount/my-membership-discounts.php

wc_memberships_members_area_my_membership_discounts_title

@since

 

1.4.0

 

@param

 

string $title the section title

 

@return

 

string – the updated title

Filters the heading for the “My Discounts” section. Example to change the heading to “Exclusive Discounts”.

wc_memberships_members_area_my_membership_discounts_column_names

@since

 

1.4.0

 

@param

 

array $columns Associative array of column ids and names

 

@param

 

int $user_id ID of logged in user

 

@return

 

array – updated array of columns

Filters the columns in the “My Discounts” section. If adding a column, be sure to also fill that column with content using the

wc_memberships_members_area_my_membership_discounts_column_{$column_id}

action.

wc_memberships_members_area_show_only_active_discounts

@since

 

1.4.0

 

@param

 

bool $show_only_active_discounts Default true

 

@param

 

int $user_id ID of logged in user

 

@param

 

int $product_id ID of discounted product

Filters whether the “My Discounts” area should list all discounts for the membership or only active discounts for the membership. Return false to show all discounts (including inactive discounts).

Membership Notes

All hooks for the “My Discounts” section of the Member Area are located in the template file: /templates/myaccount/my-membership-notes.php

wc_memberships_members_area_my_membership_notes_title

@since

 

1.4.0

 

@param

 

string $title the section title

 

@return

 

string – the updated title

Filters the heading for the “Membership Notes” section.

wc_memberships_members_area_my_membership_notes_column_names

@since

 

1.4.0

 

@param

 

array $columns Associative array of column ids and names

 

@param

 

int $user_id ID of logged in user

 

@return

 

array – updated array of columns

Filters the columns in the “My Membership Notes” section. If adding a column, be sure to also fill that column with content using the

wc_memberships_members_area_my_membership_notes_column_{$column_id}

action.

 

Actions: My Memberships

All “My Memberships” actions are located in: /templates/myaccount/my-memberships.php

wc_memberships_before_my_memberships

Fired before My Memberships table in My Account page.

wc_memberships_my_memberships_column_{$column_id}

@since

 

1.4.3

 

@param

 

WC_Memberships_User_Membership $user_membership

Fires when the column with $column_id is displayed in the My Memberships table. Used to fill a custom column with content.

wc_memberships_after_my_memberships

Fired after My Memberships table in My Account page.

 

Actions: Member Area

We have an overview of customizing the member area and adding custom sections.

wc_memberships_before_members_area

@since

 

1.4.0

 

@param

 

string $section the section ID

Fires before each section of the member area.

wc_memberships_after_members_area

@since

 

1.4.0

 

@param

 

string $section the section ID

Fires after each section of the member area.

wc_memberships_members_area_my_membership_content_column_{$column_id}

@since

 

1.4.0

 

@param

 

WP_Post $post the post object for which the row’s data is shown

located in: /templates/myaccount/my-membership-content.php

Fired for any “My Content” column added with a custom ID. Fills the table cell with content for this column. See this example.

wc_memberships_members_area_my_membership_products_column_{$column_id}

@since

 

1.4.0

 

@param

 

WC_Product $product the product object for which the row’s data is shown

located in: /templates/myaccount/my-membership-products.php

Fired for any “My Products” column added with a custom ID. Fills the table cell with content for this column.

wc_memberships_members_area_my_membership_discounts_column_{$column_id}

@since

 

1.4.0

 

@param

 

WC_Product $product the product object for which the row’s data is shown

located in: /templates/myaccount/my-membership-discounts.php

Fired for any “My Discounts” column added with a custom ID. Fills the table cell with content for this column.

wc_memberships_members_area_my_membership_notes_column_{$column_id}

@since

 

1.4.0

 

@param

 

object $note the membership note comment object for the row

located in: /templates/myaccount/my-membership-notes.php

Fired for any “My Membership Notes” column added with a custom ID. Fills the table cell with content for this column.

 

Actions: General

wc_memberships_activated

Runs when Memberships is activated.

wc_memberships_deactivated

Runs when Memberships is deactivated.

wc_memberships_duplicate_membership_plan

@since

 

1.0.0

 

@param

 

int $new_id New plan ID

 

@param

 

WP_Post $post Original plan object

located in: /includes/admin/class-wc-memberships-admin-membership-plans.php

Fires after a membership plan has been duplicated.

Table of Contents

All done here? Return to documentation overview →

Was this article helpful?
Dislike 0
Views: 16