Last active
October 10, 2015 19:17
-
-
Save BurlesonBrad/ae9169c7e51c4602de40 to your computer and use it in GitHub Desktop.
Attempt to connect Completing a Sensei LESSON to points and rewards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)
👍