Articles on: WaaS/SaaS Builder

Creating a custom integration for Dollie

Dollie's Hub Access Groups is a powerful feature in your Hub that allows you to control and monetize the services offered on your Hub/Platform. These access groups can be tied to various actions such as membership levels, product purchases, or custom integrations.

In this article we will look at the only two functions you need to write your own integration.


Function: add_to_access_group



The add_to_access_group function allows you to add a list of users to an access group.

Parameters:



$group_id (int): ID of the group.
$user_ids (array): Array of user IDs.
$source (string, optional): Source from which the users are added.
$integration (string, optional): Name of the integration.
$action (string, optional): Name of the action.

Usage:


$access = \Dollie\Core\Modules\AccessGroups\AccessGroups::instance();
    
    $group_id = 2255; // ID of the group
    $user_ids = array(2); // Array of user IDs to add
    
    $access->add_to_access_group($group_id, $user_ids, 'My Integration Trigger', 'My Integratoin', 'Added after my event/action');

Function: remove_from_access_group



The remove_from_access_group function allows you to remove a list of users from an access group.

Parameters:



$group_id (int): ID of the group.
$user_ids (array): Array of user IDs.
$source (string, optional): Source from which the users are removed.
$integration (string, optional): Name of the integration.
$action (string, optional): Name of the action.

Usage:


$access = \Dollie\Core\Modules\AccessGroups\AccessGroups::instance();
    
    $group_id = 2255; // ID of the group
    $user_ids = array(2); // Array of user IDs to remove
    
     $access->remove_from_access_group($group_id, $user_ids, 'My Integration Trigger', 'My Integratoin', 'Added after my event/action');


Code Examples



Adding a User to a Group after submitting a form in Gravity Forms



// Assuming the Gravity Forms form ID is 123 and the access group ID is 2255
add_action( 'gform_after_submission_123', 'add_user_to_group_after_submission', 10, 2 );
function add_user_to_group_after_submission( $entry, $form ) {
        $access = \Dollie\Core\Modules\AccessGroups\AccessGroups::instance();
	$user_id = $entry['created_by'];
	$access->add_to_access_group( 2255, $user_id, 'Gravity Forms Submission' );
}


Add a user to an Access Group after registration



// Assuming the user ID is 2 and the access group ID is 2255
add_action( 'user_register', 'add_user_to_group_after_registration' );
function add_user_to_group_after_registration( $user_id ) {
        $access = \Dollie\Core\Modules\AccessGroups\AccessGroups::instance();
	$access->add_to_access_group( 2255, $user_id, 'WordPress Registration' );
}


Add a user to an Access Group after purchasing a WooCommerce Product



// Assuming the WooCommerce product ID is 123 and the access group ID is 2255
add_action( 'woocommerce_order_status_completed', 'add_user_from_group_on_purchase' );
function remove_user_from_group_on_purchase( $order_id ) {
	$order = wc_get_order( $order_id );
	$user_id = $order->get_user_id();
        $access = \Dollie\Core\Modules\AccessGroups\AccessGroups::instance();
	$access->remove_from_access_group( 2255, $user_id, 'WooCommerce Purchase' );
}

Add a user to an access group after they enroll in a course in LearnDash.



// Assuming the course ID is 123 and the access group ID is 2255
add_action( 'learndash_course_enrolled', 'add_user_to_group_after_course_enrollment', 10, 2 );
function add_user_to_group_after_course_enrollment( $user_id, $course_id ) {
        $access = \Dollie\Core\Modules\AccessGroups\AccessGroups::instance();
	$access->add_to_access_group( 2255, $user_id, 'LearnDash Course Enrollment' );
}


These are just some examples but they should give you an excellent starting point to build your own integrations.

Updated on: 27/02/2024

Was this article helpful?

Share your feedback

Cancel

Thank you!