This topic has 4 replies, 3 voices, and was last updated 7 years by Radu.

  • Author
  • #174157
     psmorrow
    Participant

    Hi,

    I’m working with the Mycred plugin with the Transfer addon, and having some issues with hooking into a mycred action.  I understand if you can’t help, but the mycred support doesn’t appear to be very responsive.

    I’m trying to award a specific user points/credits each time one user transfers credits to another user.  The function I want to hook into is:  mycred_transfer_completed.

    Here is my snippet from bp-custom.php:

     

    add_action( ‘mycred_transfer_completed’, ‘add_points_for_referral’, 10, 2 );

     

    function add_points_for_referral( $transfer_id, $request ) {

     

    extract ($request);

    $transfer_amt = $request[‘amount’];

    mycred_add( ‘Transfer Bonus’, 3, 5, $transfer_amt);

    return;

    }

    As far as I can tell, the variable $request passed to the function contains no attributes.  I’ve been struggling for days on this and I’m very confused about….

    the codex for mycred_transfer_completed function is here:

    http://codex.mycred.me/actions/mycred_transfer_completed/

     

    Again, I understand if this isn’t something you can help with, but any advice/guidance you can share is much appreciated!

     

     

     

    #174266
     Laura
    Moderator

    Hello, will assign the ticket to a higher support level who can help and advise you in your query.
    Thanks! ?

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    Laura Solanes - Graphic Designer and Web Designer

    Please be patient as I try to answer each topic as fast as i can.

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Always happy to help you 🙂

    #174386
     Radu
    Moderator

    Hi,

    Did you have tried to change the priotiry to the action ? if no try with higher or lowe ones

    Also you can try to run the function when on worpdress init action or after_setup_theme or on wp_loaded , try all, see the below snippets

    COPY CODE
    function add_points_for_referral( $transfer_id, $request ) {
    
    	extract ($request);
    
    	$transfer_amt = $request['amount'];
    
    	mycred_add( 'Transfer Bonus', 3, 5, $transfer_amt);
    
    	return;
    
    }
    
    function pre_add_points_for_referral () {
    	add_action( 'mycred_transfer_completed', 'add_points_for_referral', 10, 2 );
    }
    
    add_action('init', 'pre_add_points_for_referral');
    //add_action('after_setup_theme', 'pre_add_points_for_referral');
    //add_action('wp_loaded', 'pre_add_points_for_referral');

    Hope it helps

    Cheers
    R

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #174443
     psmorrow
    Participant

    Thanks!
    Mycred documenation was out of date. The request array no longer uses the amount key; instead it uses “charge” and “payout”. Posting my new code for anyone else who might trip over this:

    COPY CODE
    add_action( 'mycred_transfer_completed', 'add_bonus_points', 10, 2 );
    function add_bonus_points( $transfer_id, $request ) {
     
        // Amount charged
        $transfer_amt = $request['charge'];
     
        // Amount actually transferred
        $transfer_amt = $request['payout'];
     
        // Senders ID
        $sender = $request['sender_id'];
     
        // Recipients ID
        $recipient = $request['recipient_id'];
     
        // Point Type
        $point_type = $request['point_type'];
     
        mycred_add( 'Transfer Bonus', 3, $transfer_amt, 'Bonus');
       
        return;
    }
    #174724
     Radu
    Moderator

    Hi,

    Thank you for providing the working solution!!

    Cheers
    R.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
Viewing 5 posts - 1 through 5 (of 5 total)

The forum ‘Plugins questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?