Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
gabrielmerovingi / mycred-woo-payout-on-completed
Last active February 10, 2024 23:07
By default myCRED will payout points for WooCommerce orders when an order has been marked as "paid". This means that no points will be paid out if a users pays using a manual gateway such as Check or Bank Transfers. This code snippet will force myCRED to payout when an order has been marked as "Completed" instead of paid.
/**
* Adjust myCRED Point Rewards
* Will move the points payout from when an order is "paid" to when
* an order is "completed".
* @version 1.0
*/
add_action( 'after_setup_theme', 'mycred_pro_adjust_woo_rewards', 110 );
function mycred_pro_adjust_woo_rewards() {
remove_action( 'woocommerce_payment_complete', 'mycred_woo_payout_rewards' );
@gabrielmerovingi
gabrielmerovingi / mycred-view-content-category-hook
Last active December 19, 2023 20:26
This custom hook allows you to reward users viewing content based on the category the post belongs to. Goes into your child theme's functions.php file or custom plugin.
/**
* Register Custom Hook
* @since 1.0
* @version 1.0
*/
add_filter( 'mycred_setup_hooks', 'mycred_pro_register_view_content_category_hook' );
function mycred_pro_register_view_content_category_hook( $installed ) {
$installed['view_category_content'] = array(
'title' => __( '%plural% for Viewing Content (Categories)', 'mycred' ),
@gabrielmerovingi
gabrielmerovingi / mycred-notifications-note-filter-example
Created January 1, 2018 14:53
Adds support for use of shortcodes in notifications.
/**
* Render Shortcodes in Notifications
* @version 1.0
*/
function mycred_pro_render_shortcodes_in_notice( $notice ) {
return do_shortcode( $notice );
}
add_filter( 'mycred_notifications_note', 'mycred_pro_render_shortcodes_in_notice' );
@gabrielmerovingi
gabrielmerovingi / mycred-log-to-bp-notification
Last active November 24, 2023 02:59
This is an example how you can add BuddyPress notifications for users when they gain / lose myCRED points.
/**
* Register Custom BP Notifications
* Inform BuddyPress about our custom myCRED related notifications.
* @since 1.0
* @version 1.0
*/
function mycredpro_register_custom_bp_notifications() {
buddypress()->mycred_notifications = new stdClass;
buddypress()->mycred_notifications->notification_callback = 'mycredpro_render_bp_notification';
@gabrielmerovingi
gabrielmerovingi / mycred-no-negative-balance
Created August 15, 2016 18:38
Prevent users from reaching a negative myCRED point balance. Will decline all point transactions that will result in a users balance going minus.
/**
* Prevent Negative Balances
* Make sure users can never get a negative balance. Will allow users
* to gain a zero balance.
* @since 1.0
* @version 1.0
*/
add_filter( 'mycred_add', 'mycred_pro_no_negative_balance', 999, 2 );
function mycred_pro_no_negative_balance( $reply, $request ) {
@gabrielmerovingi
gabrielmerovingi / mycred-take-shortcode
Last active October 21, 2022 22:19
Use this custom WordPress shortcode to deduct points from your users when they press a button.
/**
* Shortcode: Take Points
* This custom shortcode allows you to take points from your users when they
* click on the button this shortcode generates. Supports optional confirmation message.
* @version 1.0.2
*/
add_shortcode( 'mycred_take', 'mycred_pro_render_take_shortcode' );
function mycred_pro_render_take_shortcode( $atts, $label = 'Give Away' ) {
extract( shortcode_atts( array(
@gabrielmerovingi
gabrielmerovingi / Max Lottery Entries
Last active December 11, 2021 18:32
A simple example of how to adjust the myCRED Lottery add-on to add an option to set a maximum lottery entries before the lottery is closed.
/**
* Step 1 - Add new ticket preference
* In this example we will insert this under "Participation" section
* of the lottery edit screen.
* @version 1.0
*/
add_action( 'mycred_edit_lotto_participation', 'add_max_lottery_entries_settings' );
function add_max_lottery_entries_settings( $lottery ) {
$tickets = get_post_meta( $lottery->id, '_tickets', true ); ?>
@gabrielmerovingi
gabrielmerovingi / mycred-email-notice-milestones
Created March 9, 2015 16:08
Send emails to your users when they reach a certain amount of points or "milestones". This code example sends emails at three milestones: 100 points, 200 points and 300 points. Paste into your child theme's functions.php file.
/**
* Add Custom Email Instances
* First we add in our custom instances so we can select them when we create
* a new email notice.
* @version 1.0
*/
add_filter( 'mycred_email_instances', 'mycred_pro_add_milestone_email_instances' );
function mycred_pro_add_milestone_email_instances( $instances ) {
$instances['accountnum'] = array(
@gabrielmerovingi
gabrielmerovingi / mycred-publish-posttype-hook
Last active March 14, 2021 20:45
This custom myCRED hook allows you to award points for users publishing any post type on your website AND adds the option for you to award badges based on publishing specific post types.
/**
* Register Custom myCRED Hooks
* @since 1.0
* @version 1.0
*/
add_filter( 'mycred_setup_hooks', 'mycred_pro_register_publishposttype_hook' );
function mycred_pro_register_publishposttype_hook( $installed ) {
$installed['publish_posttypes'] = array(
'title' => 'Publishing Post Types',
@gabrielmerovingi
gabrielmerovingi / enforce-max-mycred-balance
Last active January 28, 2021 13:24
Example where we enforce a maximum balance of 1000 points in myCRED. If a user is about to get points that exceeds this limit, we decline the transaction. Goes into your custom plugin or child theme's functions.php file.
/**
* Enforce Maximum
* Make sure users can not earn more than 1000 points.
* @version 1.0
*/
function mycred_enforce_max_balance( $run, $request, $mycred ) {
extract( $request );
// The maximum balance a user can have