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.

The function has two parameters.

wc_memberships_get_user_membership_statuses( $with_labels = true, $prefixed = true )

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:

How to change a membership status name everywhere on your website in WooCommerce Memberships.
The status label will be changed everywhere on the website

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

Membership status names should be affected in 3rd party plugins as well
So, a huge reason reason not to hardcode membership statuses in your code 🙃

More posts about WooCommerce Memberships

Misha Rudrastyh

Misha Rudrastyh

I develop websites since 2008, so it is total of 13 years of experience, oh my gosh. Most of all I love love love to create websites with WordPress and Gutenberg, some ideas and thoughts I share throughout my blog.

Need some developer help? Contact me