diff --git a/lifterlms-groups/automatically-create-group-with-group-admin-when-purchased-via-woocommerce.php b/lifterlms-groups/automatically-create-group-with-group-admin-when-purchased-via-woocommerce.php new file mode 100644 index 0000000..ca55146 --- /dev/null +++ b/lifterlms-groups/automatically-create-group-with-group-admin-when-purchased-via-woocommerce.php @@ -0,0 +1,61 @@ +get_integration(); + $name = $integration->get_option('post_name_singular'); + $visibility = $integration->get_option('visibility') + + // Setup arguments. + $args = wp_parse_args( + $args, + array( + 'post_status' => 'publish', + 'post_title' => sprintf(__('New %s', 'lifterlms-groups'), $name), + 'meta_input' => array( + '_llms_visibility' => $visibility, + ), + ) + ); + + // Create the group. + $group = new LLMS_Group('new', $args); + + // Assign group administrator. + $order = wc_get_order($order_id); + LLMS_Groups_Enrollment::add( + $order->get_user_id(), + $group->get('id'), + 'woocommerce_order', + 'admin' + ); + + $order_data = $order->get_data(); + + // Assign the number of seats in the group. + // You're developer can modify this logic to be as custom as you want. + foreach ($order->get_items() as $item_key => $item ) { + $product = wc_get_product($item['product_id']); + $quantity = $item->get_quantity(); + $group->set('seats', $quantity); + } + } +} + +add_action('woocommerce_order_status_completed', 'create_llms_group_with_admin'); +add_action('woocommerce_order_status_processing', 'create_llms_group_with_admin'); + diff --git a/lifterlms/courses-lessons/exclude-posts-from-user-roles.php b/lifterlms/courses-lessons/exclude-posts-from-user-roles.php new file mode 100644 index 0000000..7c9c5d6 --- /dev/null +++ b/lifterlms/courses-lessons/exclude-posts-from-user-roles.php @@ -0,0 +1,54 @@ +set( 'post__not_in', $posts_to_exclude ); + return; + } + + // Check if the logged-in user has any of the specified roles. + $user_has_excluded_role = false; + $user = wp_get_current_user(); + $user_roles = (array) $user->roles; + $intersect = array_intersect( $user_roles, $roles_to_exclude ); + if ( ! empty( $intersect ) ) { + $user_has_excluded_role = true; + } + + // If the user has any of the specified roles, exclude the specific posts. + if ( $user_has_excluded_role ) { + $query->set( 'post__not_in', $posts_to_exclude ); + } +} + +add_action( 'pre_get_posts', 'exclude_posts_for_roles' );