# Sync WooCommerce Memberships with Discourse groups

**URL:** https://meta.discourse.org/t/sync-woocommerce-memberships-with-discourse-groups/118485
**Category:** Extras
**Tags:** pavilion
**Created:** [May 23, 2019, 7:13am UTC](https://meta.discourse.org/t/sync-woocommerce-memberships-with-discourse-groups/118485 "2019-05-23T07:13:06Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [May 24, 2019, 12:09am UTC](https://meta.discourse.org/t/sync-woocommerce-memberships-with-discourse-groups/118485/3 "2019-05-24T00:09:36Z")

</div>

> [@angus](#):
>
> @Simon\_Cossar if you could quickly cast your eyes over the above it would be much appreciated!

It looks correct to me. Since the site is using WordPress as the SSO provider, you could use the static `add_user_to_discourse_group` and `remove_user_from_discourse_group` functions to handle changing the group status on Discourse. That would let you do something like:

```php
	if ( in_array( $status, ACTIVE_STATUSES ) ) {
		DiscourseUtilities::add_user_to_discourse_group( $user_id, 'your_discourse_group_name' );
	} else {
		DiscourseUtilities::remove_user_from_discourse_group( $user_id, 'your_discourse_group_name' );
	}

```

Both of those functions take the user’s WordPress ID as the first argument, and a comma separated list of group names (with no spaces between the names) as the second argument. Those functions will take care of all the API credentials for you, so using them would simplify the code a bit. There are more details about those functions here: [Manage group membership in Discourse with WP Discourse SSO](https://meta.discourse.org/t/managing-discourse-group-membership-with-wp-discourse/74724).

---

_[View the full topic](https://meta.discourse.org/t/sync-woocommerce-memberships-with-discourse-groups/118485)._
