For Developers: Admin Hook Reference
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.
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: Membership Access
wc_memberships_access_granting_purchased_product_id
- @since
- 1.0.0
- @param
- int $product_id the ID that’s used for access
- @param
- array $access_granting_product_ids Array of product IDs that can grant access to this plan
- @param
- WC_Memberships_Membership_Plan $plan Membership plan access will be granted to
- @return
- int – the new product ID to use
Multiple products from a single order can grant access to a membership plan. Default behavior is to use the first product that grants access, but this can be overridden using this filter.
wc_memberships_grant_access_from_new_purchase
- @since
- 1.3.5
- @param
- bool $grant_access true by default
- @param
- array $args {
-
- @type int|string $user_id user ID for order
- @type int|string $product_id product ID that grants access
- @type int|string $order_id order ID
}
-
Filters whether membership access should be granted from the current purchase or not. Default behavior is to always grant access if a membership product is purchased.
Examples:
- Disable granting access if the customer already holds any membership
- Disable granting access if the customer already holds an active membership
wc_memberships_plan_grants_access_while_subscription_active
- @since
- 1.6.0
- @param
- bool $grants_access Default: true
- @param
- int $plan_id Membership Plan ID
Filter whether a plan grants access to a membership while subscription is active.
wc_memberships_grant_access_from_existing_purchase_order_statuses
- @since
- 1.0.0
- @param
- array $valid_order_statuses_for_grant array of order statuses
- @param
- object $plan the associated membership plan object
- @return
- array – the updated array of status
Filter the array of valid order statuses that grant access from previous purchases when the admin uses the “grant previous purchases access” action. Defaults to ‘processing’ and ‘completed’.
Example to add “Shipped” and “Invoice Paid” orders (You could also use these statuses for access during the purchasing cycle in addition to processing and completed orders, which the second function covers):
<?php // only copy this line if needed /** * Membership access is already granted when orders are processing or completed * Add membership access for custom order statuses as well * * Example: grant membership access for "Shipped" and "Invoice Paid" orders during purchase cycle as well * Use the appropriate action for your custom order status */ function sv_wc_memberships_grant_access_for_custom_order_statuses() { // bail if Memberships is not active if ( function_exists( 'wc_memberships' ) ) { add_action( 'woocommerce_order_status_shipped', array( wc_memberships()->get_plans_instance(), 'grant_access_to_membership_from_order' ), 11 ); add_action( 'woocommerce_order_status_invoice-paid', array( wc_memberships()->get_plans_instance(), 'grant_access_to_membership_from_order' ), 11 ); } } add_action( 'init', 'sv_wc_memberships_grant_access_for_custom_order_statuses', 15 ); /** * Include custom order statuses in the plan "Grant Access" action to * create new memberships as well * * Example: include "Shipped" and "Invoice Paid Orders" in "Grant Access" action for memberships * @param array $statuses orders statuses to create memberships for in "Grant access" action * @param object $plan the associated membership plan object * @return array $statuses the updated array of statuses for which to grant access */ function sv_wc_memberships_add_grant_access_order_statuses( $statuses, $plan ) { // Grant membership access to "Shipped" and "Invoice Paid" orders as well // when "Grant Access" action is used $statuses = array_merge( $statuses, array( 'shipped', 'invoice-paid' ) ); return $statuses; } add_filter( 'wc_memberships_grant_access_from_existing_purchase_order_statuses', 'sv_wc_memberships_add_grant_access_order_statuses', 10, 2 );
wc_memberships_allow_cumulative_member_discounts
- @since
- 1.7.0
- @param
- bool $cumulative true if discounts should stack across plans
- @param
- int $member_id ID for the member / WP user
- @param
- WC_Product $product
Filters whether discounts should stack if a member has more than one member discount for a product. Return false to disable stacking:
add_filter( 'wc_memberships_allow_cumulative_member_discounts', '__return_false' );
Filters: Membership Statuses
wc_memberships_user_membership_statuses
- @since
- 1.0.0
- @param
- array $statuses Associative array of statuses
- @return
- array – updated status array
Passes in an associative array of all user membership statuses, which can be used to add custom user membership statuses.
Example to add new statuses:
<?php // only copy this line if needed /** * Add custom user membership statuses * * @param array $statuses the array of membership statuses * @return array $statuses the updated status array */ function sv_wc_memberships_add_membership_statuses( $statuses ) { $new_statuses = array( 'wcm-refunded' => array( 'label' => 'Refunded', 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>' ), ), 'wcm-some-status' => array( 'label' => 'Another Status', 'label_count' => _n_noop( 'SomeStatus <span class="count">(%s)</span>', 'SomeStatus <span class="count">(%s)</span>' ), ), ); $statuses = array_merge( $statuses, $new_statuses ); return $statuses; } add_filter( 'wc_memberships_user_membership_statuses', 'sv_wc_memberships_add_membership_statuses' );
wc_memberships_active_access_membership_statuses
- @since
- 1.7.0
- @param
- array $statuses array of statuses valid for content access
Filters the user memberships status that will give the customer access to restricted content.
wc_memberships_valid_membership_statuses_for_cancel
- @since
- 1.0.0
- @param
- array $statuses Array of statuses valid for cancellation
- @return
- array – updated array of statuses
Filters the user membership statuses that can be cancelled by the customer.
wc_memberships_valid_membership_statuses_for_renewal
- @since
- 1.0.0
- @param
- array $statuses Array of statuses valid for renewal
- @return
- array – updated array of statuses
Filters the user membership statuses that can be renewed by the customer.
wc_memberships_bulk_edit_user_memberships_status_options
- @since
- 1.0.0
- @param
- array $statuses Array of bulk-edit statuses available
- @return
- array – updated array of statuses
Filter the status options available in user memberships bulk edit box.
Filters: Settings
wc_memberships_general_settings
- @since
- 1.0.0
- @param
- array $settings Array of the plugin settings
- @return
- array – updated settings array
Filters the Memberships > General Settings.
wc_memberships_products_settings
- @since
- 1.0.0
- @param
- array $settings Array of the plugin settings
- @return
- array – updated settings array
Filters the Memberships > Products Settings.
Filters: Excluded from Restriction
wc_memberships_content_restriction_excluded_post_types
- @since
- 1.0.0
- @param
- array $post_types List of post types to exclude
- @return
- array – the updated array of post types
Creates a blacklist to exclude post types from content restriction content type options. Helpful if CPTs are added from other plugins that shouldn’t be available in content restriction rules.
Example to remove Sensei Messages from posts that can be restricted:
<?php // only copy this line if needed /** * Remove post types from the membership plan restriction options * Example: remove Sensei Messages from post types that can be restricted * * @param array $blacklist the array of post types to exclude from restriction options * @return array $blacklist the updated array of post types to exclude */ function sv_wc_memberships_add_post_type_to_blacklist( $blacklist ) { $blacklist[] = 'sensei_message'; return $blacklist; } add_filter( 'wc_memberships_content_restriction_excluded_post_types', 'sv_wc_memberships_add_post_type_to_blacklist' );
wc_memberships_{$rule_type}_excluded_taxonomies
- @since
- 1.0.0
- @param
- array $taxonomies List of taxonomies to exclude
- @return
- array – updated taxonomy list
Excludes taxonomies from restriction rules. Rule type can be content_restriction
, product_restriction
, or purchasing_discount
.
Filters: Meta Boxes
wc_memberships_product_data_tabs
- @since
- 1.0.0
- @param
- array $tabs Associative array of memberships data tabs
- @return
- array – updated tab array
Filters product memberships data tabs in the Membership meta box to add or remove tabs.
wc_membership_plan_data_tabs
- @since
- 1.0.0
- @param
- array $tabs Associative array of membership plan tabs
- @return
- array – updated tab array
Filters membership plan data tabs on the edit membership plan pages.
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
Fires after a membership plan has been duplicated.
Actions: Edit User Memberships
wc_memberships_before_user_membership_notes
- @since
- 1.0.0
- @param
- WC_Memberships_User_Membership $user_membership The user membership
Fires at the beginning of the user membership notes meta box.
wc_memberships_after_user_membership_notes
- @since
- 1.0.0
- @param
- WC_Memberships_User_Membership $user_membership The user membership
Fires at the end of the user membership notes meta box.
wc_memberships_before_user_membership_member_details
- @since
- 1.0.0
- @param
- int $user_id The member (user) ID
- @param
- int $user_membership_id The post id of the user membership post
Fires at the beginning of the member details meta box.
wc_memberships_after_user_membership_member_details
- @since
- 1.0.0
- @param
- int $user_id The member (user) ID
- @param
- int $user_membership_id The post id of the user membership post
Fires at the end of the member details meta box.
wc_memberships_before_user_membership_details
- @since
- 1.0.0
- @param
- WC_Memberships_User_Membership $user_membership The user membership
Fires before the membership details in edit user membership screen.
wc_memberships_after_user_membership_details
- @since
- 1.0.0
- @param
- WC_Memberships_User_Membership $user_membership The user membership
Fires after the membership details in edit user membership screen.
wc_memberships_before_user_membership_billing_details
- @since
- 1.0.0
- @param
- WC_Memberships_User_Membership $user_membership The user membership
Fires before the billing details in edit user membership screen.
wc_memberships_after_user_membership_billing_details
- @since
- 1.0.0
- @param
- WC_Memberships_User_Membership $user_membership The user membership
Fires after the billing details in edit user membership screen.
wc_memberships_user_membership_actions_start
- @since
- 1.0.0
- @param
- int $post_id The post id of the wc_user_membership post
Fires at the start of the user membership actions meta box.
wc_memberships_user_membership_actions_end
- @since
- 1.0.0
- @param
- int $post_id The post id of the wc_user_membership post
Fires at the end of the user membership actions meta box.
Actions: Restriction Meta Boxes
wc_memberships_data_product_write_panel_tabs
Fires after the product memberships data write panel tabs are displayed.
wc_memberships_data_options_restrict_product
Fires after the product memberships data product restriction panel is displayed.
wc_memberships_data_options_grant_access
Fires after the product memberships data grant access panel is displayed.
wc_memberships_data_options_purchasing_discounts
Fires after the membership plan purchasing discounts panel is displayed.
wc_memberships_data_product_panels
Fires after the product memberships data panels are displayed.
Actions: Edit Membership Plan
wc_membership_plan_write_panel_tabs
Fires after the membership plan write panel tabs are displayed.
wc_membership_plan_options_membership_plan_data_general
Fires after the membership plan general data panel is displayed.
wc_membership_plan_options_membership_plan_data_restrict_content
Fires after the membership plan content restriction panel is displayed.
wc_membership_plan_options_membership_plan_data_restrict_products
Fires after the membership plan product restriction panel is displayed.
wc_membership_plan_options_membership_plan_data_purchasing_discounts
Fires after the membership plan purchasing discounts panel is displayed.
wc_membership_plan_options_membership_plan_members_area
Fires after the membership plan members area panel is displayed.
wc_membership_plan_data_panels
Fires after the membership plan data panels are displayed.
Actions: Membership Lifecycle
wc_memberships_grant_membership_access_from_purchase
- @since
- 1.0.0
- @param
- WC_Memberships_Membership_Plan $membership_plan The plan that user was granted access to
- @param
- array $args {
-
- @type int|string $user_id user ID for order
- @type int|string $product_id product ID that grants access
- @type int|string $order_id order ID
- @type int|string $user_membership_id post ID for the new user membership
}
-
Fires after a user has been granted membership access from a purchase.
wc_memberships_user_membership_saved
- @since
- 1.3.8
- @param
- /WC_Memberships_Membership_Plan $membership_plan The plan that user was granted access to
- @param
- array $args {
-
- @type int|string $user_id user ID for the membership
- @type int|string $user_membership_id post ID for the new user membership
- @type bool $is_update true if the membership is being updated, false if new
}
-
Fires after a user has been granted membership access, either from purchase, from programmatically creating memberships, or from admin action.
wc_memberships_user_membership_created
- @since
- 1.3.8
- @param
- /WC_Memberships_Membership_Plan $membership_plan The plan that user was granted access to
- @param
- array $args {
-
- @type int|string $user_id user ID for the membership
- @type int|string $user_membership_id post ID for the new user membership
- @type bool $is_update true if the membership is being updated, false if new
}
-
Fires after a user has been granted membership access. This action hook is similar to wc_memberships_user_membership_saved
, but won’t fire when memberships are manually created from admin.
wc_memberships_cancelled_user_membership
- @since
- 1.0.0
- @param
- int $user_membership_id
Fires right after a user membership has been cancelled by the customer.
wc_memberships_user_membership_status_changed
- @since
- 1.0.0
- @param
- WC_Memberships_User_Membership $user_membership
- @param
- string $old_status Old status, without the wcm- prefix
- @param
- string $new_status New status, without the wcm- prefix
Fires when user membership status is updated.
Here’s an example of a basic handler to change user roles based on active / inactive membership status.
wc_memberships_new_user_membership_note
- @since
- 1.0.0
- @param
- array $data {
-
- @type int|string $user_membership_id post ID for the new user membership
- @type object $note the user membership note (comment object) added
- @type bool $notify true if the member will be notified
}
-
Fires after a new membership note is added.
User Documentation
All done here? Return to documentation overview →