Created
July 31, 2018 01:46
-
-
Save danieljwonder/d0e3463241be0c28f54fe5a5938e0384 to your computer and use it in GitHub Desktop.
Add user to `Members` Discourse Group if active WooCommerce Memberships plan is found.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Add user to `Members` group if active WooCommerce Memberships plan is found. | |
| * | |
| * @params array $params wpdc sso data | |
| * @return array $params wpdc sso data including `Members` group status | |
| */ | |
| function wpdc_wc_memberships_add_to_dc_group( $params ) { | |
| // Bail if Memberships isn't active | |
| if ( ! function_exists( 'wc_memberships' ) ) { | |
| return $params; | |
| } | |
| // Get any active user memberships (requires Memberships 1.4+) | |
| $user_id = get_current_user_id(); | |
| $args = array( | |
| 'status' => array( 'active', 'complimentary', 'pending', 'free_trial' ), | |
| ); | |
| $active_memberships = wc_memberships_get_user_memberships( $user_id, $args ); | |
| // Check for active memberships to enable `Members` access | |
| if ( ! empty( $active_memberships ) ) { | |
| // Add to `Members` group on Discourse | |
| $params['add_groups'] = 'Members'; | |
| } else { | |
| // Remove from `Members` group on Discourse | |
| $params['remove_groups'] = 'Members'; | |
| } | |
| return $params; | |
| } | |
| add_filter( 'wpdc_sso_params', 'wpdc_wc_memberships_add_to_dc_group' ); |
Same here, code doesn't work
Author
@tomrobak if it is here it would have been working at the time. However, it has been four years since this was posted so it s very likely that things have changed in the relevant plugins and I'm no longer using this code so not sure what the current solution would be. Hopefully this can act as a starting point. Good luck!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @danielmcclure . I've added this to my WP/Woo site and have the Wordpress Discourse plugin activated. There are members that should be added to the group I created on Discourse and added to your code but it's not happening. Have I missed anything? Does WP have to be the SSO Provider, for example? Are there other requirements for this to work? Thanks for any guidance you can offer.