Teams for WooCommerce Memberships Developer Documentation

This document provides an overview of structure, hooks, and helpful methods in Teams for WooCommerce Memberships. To make adjustments to plugin functionality in an upgrade-safe manner, you should be very familiar with WordPress hooks — actions and filters — as these allow you to make modifications to plugin behavior.

Our goal is to ensure this plugin is easy to work with for customizations. If a hook doesn’t exist where you think it should, please submit a ticket so we can consider its addition.

This reference lists helpful filters, actions, and methods and is meant to be a directory. This document may not outline every available or hook or method, so please see the plugin’s inline documentation for additional details on parameters, returned values, and usage, or example usage.

Please be aware that this document is meant for developers to use as a reference, and some of these code samples are structural samples rather than working snippets. We do not support or do plugin customizations as per our support policy. You can get in touch with an expert for help with customizations.

If you need help changing this code or extending it, we recommend getting in touch with a WooExpert or a developer at Codeable.

Please be aware that the plugin namespace is: \SkyVerge\WooCommerce\Memberships\Teams — references to classes in this document will prefix global namespaces or complete namespaces with a backslash (\); a relative class name, such as “Team”, implies that this object would live in the plugin namespace, such as: \SkyVerge\WooCommerce\Memberships\Teams\Team

Data Structure ↑ Back to top

Teams for WC Memberships leverages a few custom data structures, but you would also benefit from being familiar with the data structure of WooCommerce Memberships itself. The Memberships Data Structure overview and developer documentation will be helpful resources.

We also recommend reviewing the methods in the WC_Memberships_User_Membership class, as these methods are quite commonly used by developers to manipulate user memberships. User memberships can easily be instantiated with the wc_memberships_get_user_membership() global method.

For its own functionality, Teams adds a “team” and “invitation” custom post type to manage groups of members, and invitations to join a team. Teams also makes modifications to particular products and membership plans to store additional data related to purchasing a team, and managing team access.

Teams ↑ Back to top

Post type: wc_memberships_team

The team post serves as a data store for all team information, such as purchase record, owner, and members (along with the roles of each member on the team).

The team owner is stored as the post_author, given a team can only have one owner, and the configured team name is stored as the post_title. The team’s post_parent is the post ID of the Membership Plan to which the team grants access (as currently a team can only provide access to a single plan).

Team posts store other data about the team as well:

meta key data type stored value
_product_id int the ID for the product that was purchased to create the team
_order_id int the ID for the order in which the team was purchased
_subscription_id int if the team was purchased via a subscription product, this is the ID of the subscription to which access is tied
_seat_count int the maximum number of available seats on this team
_member_id int the ID of a member on the team; there can be multiple pieces of _member_id metadata if multiple seats are occupied
_membership_end_date string the day membership start to expire, based on the plan length; owners cannot remove members after this date if removals are enabled

Team Invitation ↑ Back to top

Post type: wc_team_invitation

Invitation posts store data about invitations sent to particular emails. The invitation post will use custom statuses to determine the invitation status: wcmti-pending, wcmti-accepted, or wcmti-cancelled. The post_author is the user who sent the invitation, while the post_parent is the team to which the invitation belongs.

Pending invitations will store no meta, but accepted invitations will add 2 pieces of meta data:

meta key data type stored value
_accepted_user_id int the user ID of the customer who accepted the invitation
_accepted_date string the date on which the invitation was accepted

Product Data ↑ Back to top

To associate a team with a product or variation, the product post will store a few pieces of data:

meta key data type stored value
_wc_memberships_for_teams_has_team_membership string yes or no
_wc_memberships_for_teams_pricing string per_member or per_team (dictates the pricing fields for the team)
_wc_memberships_for_teams_max_member_count int the maximum seats that a team can have upon purchase
_wc_memberships_for_teams_min_member_count int the minimum seats required to purchase a team
_wc_memberships_for_teams_plan int the ID of the membership plan to which the team will have access

User capabilities ↑ Back to top

Teams provides a few custom WP User capabilities for both admin management of teams, and frontend management for team owners and managers.

capability description default roles
memberships_team grants admin access to manage teams WP: administrator
WP: shop manager
wc_memberships_for_teams_renew_team_membership lets a user renew team access team owner
wc_memberships_for_teams_manage_team_settings lets a user manage team settings (e.g., name) team owner
wc_memberships_for_teams_manage_team
wc_memberships_for_teams_manage_team_members
lets a user manage a team and which members belong team owner
team manager
wc_memberships_for_teams_remove_team_member lets a user remove team members team owner
team manager

Team Lifecycle ↑ Back to top

You can hook into the team lifecycle at several instances to fire third party code or adjust teams.

Created Team Filters ↑ Back to top

When a new team is created, the team data can be filtered.

wc_memberships_for_teams_new_team_data

@since
1.0.0
@param
array $data team data
@param
array $args an array of team arguments {

  • @type string $name the team name
  • @type int $plan_id the plan id the team has access to
  • @type int $owner_id the user id the team is assigned to
  • @type int $product_id the product id that creates the team (optional)
  • @type int $order_id the order id that contains the product that creates the team (optional)
  • }

Created Team Actions ↑ Back to top

Team creation and management also fires several actions that can be used to run additional code.

wc_memberships_for_teams_team_created

Fires after a team has been created. This action hook is similar to wc_memberships_for_teams_team_saved but doesn’t fire when teams are manually created from admin.

@since
1.0.0
@param
Team $team the team that was just created
@param
bool $updating whether this is a post update or a newly created team

wc_memberships_for_teams_team_saved

Fires after a team has been created. This action hook is similar to wc_memberships_for_teams_team_created but will also fire when a team is manually created in admin, or upon an import or via command line interface, etc.

@since
1.0.0
@param
Team $team the team that was just saved
@param
bool $updating whether this is a post update or a newly created team

wc_memberships_for_teams_process_team_meta

Fires when a team is saved/updated from admin.

@since
1.0.0
@param
int $post_id post identifier
@param
\WP_Post $post the post object

Invitation Lifecycle ↑ Back to top

You can hook into the team lifecycle at several instances to fire third party code or adjust invitations.

Created Invitation Filters ↑ Back to top

When a new invitation is created, the invitation data can be filtered.

wc_memberships_for_teams_new_invitation_post_data

@since
1.0.0
@param
array $data new invitation post data
@param
array $args array of Invitation arguments {

  • @type string $email email of the invitation recipient
  • @type int $team_id the team id
  • @type int $sender_id the sender user id
  • @type string $role the role to assign the invited user to
  • }

Created Invitation Actions ↑ Back to top

Invitation creation will also fire an action that can be used to run additional code.

wc_memberships_for_teams_invitation_created

Fires after an invitation has been created.

@since
1.0.0
@param
\SkyVerge\WooCommerce\Memberships\Teams\Invitation $invitation the invitation that was just created

Frontend Hooks ↑ Back to top

This is a non-exhaustive list; these represent some often-used frontend hooks.

Frontend Filters ↑ Back to top

wc_memberships_for_teams_product_team_user_input_fields

Filters user input fields for a team product.

@since
1.0.0
@param
array $fields associative array of user input fields
@param
\WC_Product $product the product

wc_memberships_for_teams_add_team_member_form_fields

Filters form fields for the add team member form on frontend.

@since
1.0.0
@param
array $fields associative array of form fields

wc_memberships_for_teams_add_team_member_form_fields

Filters form fields for the add team member form on frontend.

@since
1.0.0
@param
array $fields associative array of form fields

wc_memberships_team_teams_area_sections

Filters the available sections for the teams area.

@since
1.0.0
@param
array $sections associative array with teams area id and label of each section

wc_memberships_for_teams_teams_area_{$section_id}_title

Filters the teams area section name title. Core section IDs include “members”, “add-member”, and “settings”.

@since
1.0.0
@param
string $section_name the section name (e.g. “Members”, “Add Member”, “Settings”…)
@param
Team $team the current team displayed

wc_memberships_for_teams_teams_area_my_team_details

Filters the teams area team details.

@since
1.0.0
@param
array $details associative array of settings labels and HTML content for each row
@param
Team $team the team the details are for

Frontend Actions ↑ Back to top

wc_memberships_for_teams_before_renewal_auto_login

Fires right before logging a team member in. Can throw \SV_WC_Plugin_Exception to halt the login completely.

@since
1.0.0
@param
int $log_in_user_id the user ID of the member to log in
@param
\SkyVerge\WooCommerce\Memberships\Teams\Team $team team instance
@param
bool $allow_login whether automatic log in is allowed

Admin Hooks ↑ Back to top

This is a non-exhaustive list; these represent some often-used admin hooks.

Admin Filters ↑ Back to top

wc_memberships_for_teams_team_member_roles

Filters the list of available team member roles. Note that this does not include owner by design.

@since
1.0.0
@param
array $roles an associative array of role => label pairs

wc_memberships_for_teams_settings

Filters Memberships for Teams settings.

@since
1.0.0
@param
array $settings array of teams settings

wc_memberships_for_teams_invitation_statuses

Filters invitation statuses.

@since
1.0.0
@param
array $statuses associative array of statuses and their arguments

Admin Actions ↑ Back to top

wc_memberships_for_teams_before_team_billing_details

Fires before the billing details in edit team screen.

@since
1.0.0
@param
\SkyVerge\WooCommerce\Memberships\Teams\Team $team the team instance

wc_memberships_for_teams_after_team_billing_details

Fires before the billing details in edit team screen.

@since
1.0.0
@param
\SkyVerge\WooCommerce\Memberships\Teams\Team $team the team instance

Methods and Global Functions ↑ Back to top

This is a non-exhaustive list; these represent some often-used plugin methods.

Plugin main class ↑ Back to top

The instance of the main plugin class can be accessed with: wc_memberships_for_teams()

Any other plugin classes are instantiated in this main plugin class, or another class that’s instantiated by the main plugin class. Therefore, if you want to unhook methods in a particular class, you’ll need to use this helper to access the class instance. For example, many classes are instantiated by the main plugin class, and can be accessed with:

wc_memberships_for_teams()->get_*_instance()

For example:

wc_memberships_for_teams()->get_orders_instance()

Classes that are not instantiated in the main plugin class can be accessed through instances of the class that instantiates them:

wc_memberships_for_teams()->get_frontend_instance()->get_teams_area_instance()

Teams object ↑ Back to top

While we won’t list every method here, the Team object is a good one to review, as this provides methods to get or set almost any piece of team data, or programmatically process seat changes, member invites, adding or removing members, etc.

An instance of this class can be accessed with:

wc_memberships_for_teams_get_team( $team_id_or_post )

Conditional Checks ↑ Back to top

There are a few conditional checks that can help you determine team or product information.

wc_memberships_for_teams_is_valid_team_member_role( $role )

Checks if a team member role is valid or not.

@since
1.0.0
@param
string $role the role to check

\SkyVerge\WooCommerce\Memberships\Teams\Product::has_team_membership( $product )

Checks if a product has a team membership attached (purchasing this product creates a team). You must pass an instance of WC_Product to this method.

@since
1.0.0
@param
\WC_Product $product

\SkyVerge\WooCommerce\Memberships\Teams\Product::has_per_member_pricing( $product )

Checks if a product uses per-member pricing (false if per-team pricing is used). You must pass an instance of WC_Product to this method.

@since
1.0.0
@param
\WC_Product $product

Global & Static Functions ↑ Back to top

A non-exhaustive list of some helpful global and static methods for use in customizations.

\SkyVerge\WooCommerce\Memberships\Teams\Product::get_min_member_count( $product )

Gets the minimum member count required to purchase the team product; returns the integer count or null if not set. You must pass an instance of WC_Product to this method.

@since
1.0.0
@param
\WC_Product $product

\SkyVerge\WooCommerce\Memberships\Teams\Product::get_max_member_count( $product )

Gets the maximum member count allowed when purchasing the team product; returns the integer count or null if not set. You must pass an instance of WC_Product to this method.

@since
1.0.0
@param
\WC_Product $product

\SkyVerge\WooCommerce\Memberships\Teams\Product::get_membership_plan_id( $product )

Gets the membership plan ID that will be granted to a team created via this product; returns the integer count or null if not set. You must pass an instance of WC_Product to this method.

@since
1.0.0
@param
\WC_Product $product

wc_memberships_for_teams_get_team( $id_or_post )

Can be used to get an instance of a team. Accepts the team post object or post ID. Returns a Team instance if found, or false on failure.

@since
1.0.0
@param
int|\WP_Post $post optional team id or post object, defaults to current global post object

wc_memberships_for_teams_get_teams( $user_id, $args, $return, $force_refresh )

Returns a list of teams for a user (should be preferred over get_posts() calls to protect against data structure changes). Can return either a plain list of team objects or an associative array with query results and team objects, and will return false on failure.

@since
1.0.0
@param
int $user_id optional, defaults to current user
@param
array $args an array of arguments to pass to \WP_Query – additionally, a few special arguments can be passed: {

  • @type string|array $status team status, defaults to ‘any’
  • @type string|array $role a comma-separated list or array of team member roles, defaults to ‘owner, manager’ – specifying this will only fetch teams that the user has one of the given roles
  • @type int $paged the page number for paging the results (corresponds to paged param for get_posts())
  • }

@param
string $return (optional) what to return – set to ‘query’ to return the \WP_Query instance instead of a list of invitation instances
@param
bool $force_refresh (optional) whether to force reloading the results even if a previous result has been memoized, defaults to false

wc_memberships_for_teams_get_user_membership_team( $user_membership_id )

Returns the team for a given user membership, if any. Returns false if the membership does not belong to a team.

@since
1.0.0
@param
int $user_membership_id user membership id

wc_memberships_for_teams_get_team_members( $team_id, $args, $return, $null )

Returns a list of team members given the input query (should be preferred over get_posts() calls to protect against data structure changes). Can return either a plain list of team member objects or an associative array with query results and team member objects.

@since
1.0.0
@param
int|\SkyVerge\WooCommerce\Memberships\Teams\Team $team_id team id or instance to get the team members for
@param
array $args (optional) an array of arguments to pass to \WP_Query – additionally, a few special arguments can be passed: {

  • @type string|array $role a comma-separated list or array of team member roles, empty by default – specifying this will only fetch members with the given role
  • @type int $paged the page number for paging the results, corresponds to paged param for get_users()
  • @type int $per_page the number of team members to fetch per page, corresponds to the number param for get_users()
  • }

@param
string $return (optional) what to return – set to ‘query’ to return the \WP_User_Query instance instead of a list of team member instances
@param
bool $force_refresh (optional) whether to force reloading the results even if a previous result has been memoized, defaults to false

wc_memberships_for_teams_get_team_member_roles()

Returns a an associative array of available team member roles.

@since
1.0.0

wc_memberships_for_teams_create_team( $args )

Programmatically creates a team. Returns a new Team object on success which can then be used to add additional data, but will return \SV_WC_Plugin_Exception on failure.

@since
1.0.0
@param
array $args (see below)
@param
string $action ‘create’ or ‘renew’; defaults to ‘create’
@return
Team|\SV_WC_Plugin_Exception

The arguments you can pass in to create a new team are as follows:

array key data type required value
owner_id int required owner user ID
plan_id int|\WC_Memberships_Plan required plan ID or instance to which the team will have access
product_id int|\WC_Product product ID or instance that can be used to purchase the team; required if a team should be renewable
order_id int\WC_Order ID or instance of the order in which the team was purchased
name string team name; defaults to “Team”
seats int the seat count for the team; if not provided, product_id must be specified, and the team will use the max member count from the product/variation

wc_memberships_for_teams_create_invitation( $args )

Programmatically creates a team invitation. Returns a new Invitation object on success which can then be used to add additional data, but will throw \SV_WC_Plugin_Exception on failure.

@since
1.0.0
@param
array $args (see below)
@return
Invitation|\SV_WC_Plugin_Exception

The arguments you can pass in to create a new invitation are as follows:

array key data type required value
team_id int|object required team ID or instance for the invitation
email string required the email address to which the invitation should be sent
sender_id int the sender’s user ID (default: current user)
role string the team role to assign to the invited user, defaults to ‘member’

wc_memberships_for_teams_get_invitation( $id, $email )

Returns a specific invitation for a team, or false on failure.

@since
1.0.0
@param
string|int|\WP_Post|Invitation|Team $id invitation token, id, or instance; or team id or instance
@param
string $email (optional) invitation recipient email, required if $id is a team id or instance

wc_memberships_for_teams_get_invitations( $team_id, $args, $return, $force_refresh )

Returns a list of invitations (should be preferred over get_posts() calls to protect against data structure changes). Can return either a plain list of invitation objects or an associative array with query results and invitation objects.

@since
1.0.0
@param
int $team_id team id to get the invitations for
@param
array $args an array of arguments to pass to \WP_Query – additionally, a few special arguments can be passed: {

  • @type string|array $status invitation status, defaults to ‘pending’, can be used instead of $post_status
  • string|array $role a comma-separated list or array of team member roles, empty by default – specifying this will only fetch invitations that grant the one of thge specified roles for the user
  • @type int $paged the page number for paging the results, corresponds to paged param for get_posts()
  • @type int $per_page the number of invitations to fetch per page, corresponds to the posts_per_page param for get_posts()
  • }

@param
@param string $return (optional) what to return – set to ‘query’ to return the \WP_Query instance instead of a list of invitation instances
@param
bool $force_refresh (optional) whether to force reloading the results even if a previous result has been memoized, defaults to false

User Documentation ↑ Back to top

Return to user documentation →

WooCommerce - the most customizable eCommerce platform for building your online business.

Back to the top