Skip to content

Instantly share code, notes, and snippets.

@BurlesonBrad

BurlesonBrad/Sensei Points

Last active Oct 10, 2015
Embed
What would you like to do?
Attempt to connect Completing a Sensei LESSON to points and rewards
<?php
// THIS IS THE FILE FROM https://gist.github.com/woogist/5692886#file-gistfile1-php//
// ...and, believe it or not, I understand about 50% of this.//
// While that's better than the average Joe, it' still not enough to actually CONNECT the points //
// Anyone want to jump in here? //
// Add the action setting
add_filter( 'wc_points_rewards_action_settings', 'bkg_sensei_points' );
function points_rewards_newsletter_action_settings( $settings ) {
$settings[] = array(
'title' => __( 'Points earned for completing lesson' ),
'desc_tip' => __( 'Enter the amount of points earned when a customer finishes a Sensei Lesson.' ),
'id' => 'bkg_sensei_points',
);
return $settings;
}
// add the event descriptions
add_filter( 'wc_points_rewards_event_description', 'one_of_those_magical_hook_things_goes_here', 10, 3 );
function one_of_those_magical_hook_things_goes_here( $event_description, $event_type, $event ) {
$points_label = get_option( 'wc_points_rewards_points_label' );
// set the description if we know the type
switch ( $event_type ) {
case 'magical_underlined_thing': $event_description = sprintf( __( '%s earned for newsletter signup' ), $points_label ); break;
}
return $event_description;
}
// perform the event (of course this depends on your particular plugin/action)
add_action( 'wp_mailchimp_new_newsletter_signup', 'yet_another_underscore_thingy' );
function yet_another_underscore_thingy( $lesson_id ) {
// can't give points to a user who isn't logged in
if ( ! is_user_logged_in() )
return;
// get the points configured for this custom action
$points = get_option( 'wc_points_rewards_mailchimp_newsletter_signup' );
if ( ! empty( $points ) ) {
// arbitrary data can be passed in with the points change, this will be persisted to the points event log
$data = array( 'lesson_id' => $lesson_id );
WC_Points_Rewards_Manager::increase_points( get_current_user_id(), $points, 'magical_underlined_thing', $data );
}
}
@BurlesonBrad

This comment has been minimized.

Copy link
Owner Author

@BurlesonBrad BurlesonBrad commented Sep 10, 2015

thinking more about user behavior....
Somehow, there should be points that are assigned for completing a quiz (not lesson):
The shop owner would want to turn OFF the ability to complete the lesson. Then they'd assign points for successfully completing the QUIZ (not the lesson! ~duh Brad!!) Those points would then be awarded as whatever the shop owner wanted! like merchandise, or another class, or a free month of a subscription, or anything else that the store owner wanted.
The point being: Adding POINTs helps users STAY engaged. This would be ESPECIALLY important for anyone running a subscription based Sensei site!

@BurlesonBrad

This comment has been minimized.

Copy link
Owner Author

@BurlesonBrad BurlesonBrad commented Sep 10, 2015

wait. I think I'm getting closer to the answer! Run over to
http://docs.woothemes.com/document/sensei-theming/
and scroll down 'till ya find:


sensei_after_completed_user_courses – runs when a user’s courses are outputted, specifically after the completed courses.
sensei_after_user_courses – runs after a user’s courses are outputted.
sensei_course_results_content – outputs the course results page content.
sensei_course_results_info – outputs the course results page info.


The answer is somewhere in there!!! (....I think)
👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.