Use Code: “StayHome” to avail an exclusive 30% DISCOUNT on myCred Membership Club’s yearly pricing plans! Click Here To Get Started

Using a badge ID for accessing protected pages.

front page Forums Community Using a badge ID for accessing protected pages.

This topic contains 3 replies, has 3 voices, and was last updated by Avatar Mr Graylien 3 months, 1 week ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #45605
    Avatar
    WeirdMike

    I was looking for a way to allow someone to purchase a product with one kind of points, which in turn rewards them with a badge.
    I would then like to be able to grant access to a protected page for those who have that badge in their inventory (if you will) by using the badge ID.

    Is this possible?

    #45884
    Avatar
    M

    Hi @weirdmike,

    There is no built-in shortcode to do this. However, it is perfectly possible to accomplish using some custom code.

    Cordially, M.

    #46221
    Avatar
    Mr Graylien

    This could be added to the page through a shortcode or directly in the page template..

    `<?php

    $badge_id_access = 1718;
    $user_id = get_current_user_id();
    $badge_ids = mycred_get_users_badges( $user_id );

    if (array_key_exists($badge_id_access, $badge_ids)) {
    echo “ACCESS GRANTED”; // You could add your content in here. Or another unlock variable from a page/access manager?
    } else {
    echo “ACCESS DENIED”; }

    ?>’

    #46222
    Avatar
    Mr Graylien
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

11