
How to get admin user ID
Share This Post How to get admin User ID? It’s been really difficult for many to get back the admin user ID but it’s so
It’s very common to award GamiPress points/badges/ranks on users’ visit at any page on GamiPess site according to its default achievement system and surely there isn’t any option to award points/badges/ranks on visiting custom post-type posts only, but how amazing it is, if you eagerly like to add this feature simply to GamiPress and experience it.
All the snippets below will be used for WooCommerce “Product” post-type. As an example. Users will be getting points/badges/ranks on visiting WooCommerce products or specific product pages.
Note: GamiPress and WooCommerce plugins must be configured in order to use these snippets.
Let’s Check it now;
This snippet will add a new trigger (heading) to GamiPress as rest of the default triggers shown in drop down.
/**
* Add new trigger to the gamipress
*/
function ldninjas_gamipress_new_trigger( $triggers ) {
$triggers['Award Points on Visiting WooCommerce Products'] = array(
'visiting_woocommerce_product' => __( 'On visiting WooCommerce Product', 'gamipress-new-trigger' ),
);
return $triggers;
}
add_filter( 'gamipress_activity_triggers', 'ldninjas_gamipress_new_trigger' );
This snippet will easily list all the WooCommerce products to the triggers.
/**
* List WooCommerce Products to the trigger
*/
function ldninjas_specific_activity_trigger_completing_lesson( $specific_triggers ) {
$specific_triggers['visiting_woocommerce_product'] = array( 'product' );
return $specific_triggers;
}
add_filter( 'gamipress_specific_activity_triggers', 'ldninjas_specific_activity_trigger_completing_lesson' );
This snippet will be used to display label on GamiPress activity log.
/**
* Title for sub trigger
*/
function ldninjas_specific_activity_trigger_label( $specific_trigger_labels ) {
$specific_trigger_labels['visiting_woocommerce_product'] = __( 'Visit WooCommerce Products', 'gamipress-new-trigger' );
return $specific_trigger_labels;
}
add_filter( 'gamipress_specific_activity_trigger_label', 'ldninjas_specific_activity_trigger_label' );
This snippet will award points/badges/ranks to WooCommerce/specific products on visiting it.
/**
* Award Points/Badges/ranks
*/
function ldninjas_award_points_on_visiting_woo_product() {
if( is_admin() || ! is_user_logged_in() || ! is_product() ) {
return;
}
gamipress_trigger_event( array(
'event' => 'visiting_woocommerce_product',
'user_id' => get_current_user_id(),
'specific_id' => get_the_ID()
) );
}
add_action( 'wp', 'ldninjas_award_points_on_visiting_woo_product' );
So, All you need to add this code snippet to your theme functions.php file to award points/badges/ranks on visiting custom post-type posts only. Enjoy!
Share This Post How to get admin User ID? It’s been really difficult for many to get back the admin user ID but it’s so
Share This Post Award GamiPress on RCPro Membership Renewal Do you think users can also be awarded points/badges/ranks while RCPro Membership renewal? Yes, you can
Share This Post Custom Message with myCRED Transfer MyCred assigns different points to the users but it’s been sometime noticed that the users want to
Once you send the details, we will be shortly back to you. Thanks!
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.