This Plugin allows you to Sync WooCommerce Memberships with Discourse Groups.
Pre-requisites
For this to work you have to have DiscourseConnect enabled, with either Wordpress or Discourse as the DiscourseConnect provider.
Steps
-
Install this Wordpress plugin GitHub - paviliondev/discourse-woocommerce.
-
Use the Wordpress theme editor to update these numbers to the WooCommerce plan_id and Discourse group id and group_name you want to sync
$member_group_map[] = (object) array('plan_id' => 51, 'group_id' => 43, 'group_name' => 'group1'); $member_group_map[] = (object) array('plan_id' => 62, 'group_id' => 44, 'group_name' => 'group2');
You can add as many entries as you like (or remove existing ones).
-
WooCommerce membership plan ids can be found in the url while editing the plan in Wordpress: https://site/wp-admin/post.php?post=441&action=edit
-
Discourse group id can be found here: https://site.com/groups/group_name.json
-
Optional Step
- Install WP Crontrol â WordPress plugin | WordPress.org and schedule
run_full_wc_membership_sync
to run every 24 hours. This will do a full sync to ensure consistency.
Technical Notes
The only reliable way to capture both membership creation and status change in WooCommerce is using the wc_memberships_user_membership_saved
admin hook. You can use this in combination with the wc_memberships_user_membership_status_changed
hook, but it should not be necessary.
This code uses the WooCommerce logger to log info to /wp-content/uploads/wc-logs/{log_file}
. If it is not working check the output there. You will see a logs that look like this, showing you the stages of the logic:
2019-05-23T07:01:57+00:00 INFO Running handle_wc_membership_saved 1, 92, 1
2019-05-23T07:01:57+00:00 INFO angus@email.com membership of VIP Membership changed to wcm-active
2019-05-23T07:01:57+00:00 INFO Sending PUT request to http://localhost:3000/groups/41/members with angus@email.com
2019-05-23T07:01:57+00:00 INFO Response from Discourse: 200 OK
Usage Notes
The Sync will not work if you click âDelete User Membershipâ in the Wordpress admin panel. There is no hook in WooCommerce that fires when that is clicked. Change the status of the membership instead.