Get Plan Statuses in WooCommerce Memberships
Today I am going to talk a little bit about this function wc_memberships_get_user_membership_statuses()
– it allows to get all the statuses, so you do not have to hardcode them anywhere, and I will tell you more – if you hardcode the membership statuses in your plugin or theme, these statuses can be filtered in another plugin later which will definitely break everything you built 😁
The function return an array of available statuses in this format:
$statuses = array(
'wcm-active' => array(
'label' => _x( 'Active', 'Membership Status', 'woocommerce-memberships' ),
'label_count' => _n_noop( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', 'woocommerce-memberships' ),
),
'wcm-delayed' => array(
...
And so on for every status. The default ones are listed below but as I mentioned before, there could be some custom created statuses.
wcm-active
– Activewcm-delayed
– Delayedwcm-complimentary
– Complimentarywcm-pending
– Pending cancellationwcm-expired
– Expiredwcm-cancelled
– Cancelled
The function has two parameters.
wc_memberships_get_user_membership_statuses( $with_labels = true, $prefixed = true )
$with_labels
– if set tofalse
, the function will return an array with only statuses names, like[ 'wcm-active', 'wcm-delayed' ... ]
$prefixed
if set tofalse
, the status names will be without thewcm-
prefix.
Filtering Membership Statuses
The function has this filter hook inside – wc_memberships_user_membership_statuses
. I recommend you to be super careful with this hook especially when you decided to remove some core statuses.
Change WooCommerce Memberships Status Name
Let’s keep things simple for now and try to change the Active status label for example.
add_filter( 'wc_memberships_user_membership_statuses', function( $statuses ) {
$statuses['wcm-active']['label'] = 'New status label';
return $statuses;
} );
Here is the result:

Also look, this change now affects my plugin settings too.

More posts about WooCommerce Memberships

Misha Rudrastyh
Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me