BuddyDev

Search

Donation feature for buddypress

  • Participant
    Level: Guru
    Posts: 731
    Tosin on #40228

    I have tested this several times now this section below does not display any text for empty fields

    return $content . __( ‘Following details are missing’ ) . join( ‘ & ‘, $missing_details );

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2487
    Ravi on #40235

    Hello Tosin,

    Missing details will not show until all fields are empty.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 731
    Tosin on #40238

    thats exactly my point see image https://ibb.co/HNZrFBy

    Sorry for the trouble

    This is my code

    
     add_filter( 'the_content', function ( $content ) {
    
    	// Our donation page link.
    	if ( ! is_page( 36918 ) || ! isset( $_GET['user_id'] ) || ! $_GET['nonce'] ) {
    		return $content;
    	}
    
    	$user = get_user_by( 'id', absint( $_GET['user_id'] ) );
    
    	if ( ! $user || ! wp_verify_nonce( $_GET['nonce'], 'donate-' . $user->ID ) ) {
    		return $content;
    	}
    
    	$bank_name               = xprofile_get_field_data( 3217, $user->ID );
    	$account_number          = xprofile_get_field_data( 3218, $user->ID );
    	$account_name            = xprofile_get_field_data( 3219, $user->ID );
    	$paystack_url            = xprofile_get_field_data( 3220, $user->ID );
    	$crypto_currency_name    = xprofile_get_field_data( 4447, $user->ID );
    	$crypto_currency_address = xprofile_get_field_data( 4446, $user->ID );
    
    	$missing_details = array();
    
    	// Replace field id with your one mandatory for donation. If empty return your message.
    	if ( empty( $bank_name ) ) {
    		$missing_details[] = __( 'Bank name has not been provided' );
    	}
    	if ( empty( $account_number ) ) {
    		$missing_details[] = __( 'Account number has not been provided' );
    	}
    	if ( empty( $account_name ) ) {
    		$missing_details[] = __( 'Account name has not been provided' );
    	}
    	if ( empty( $paystack_url ) ) {
    		$missing_details[] = __( 'Paystack URL has not been provided' );
    	}
    	if ( empty( $crypto_currency_name ) ) {
    		$missing_details[] = __( 'Cryptocurrency name has not been provided' );
    	}
    	if ( empty( $crypto_currency_address ) ) {
    		$missing_details[] = __( 'Cryptocurrency address has not been provided' );
    	}
    
    	$render_shortcode = false;
    
    	if ( $bank_name || $account_number || $account_name || $paystack_url || $crypto_currency_name || $crypto_currency_address ) {
    		$render_shortcode = true;
    	}
    
    	if ( ! $render_shortcode ) {
    		return $content . __( 'This member has not provided any payment details, the following payment details are missing: ' ) . join( ' & ', $missing_details );
    	}
    
    	ob_start();
    
    	// Replace group_id to your group id.
    	echo do_shortcode( "[bpsc-user-avatar user_id={$user->ID}]" );
    	echo do_shortcode( "[bpsc-user-display-name user_id={$user->ID}]" );
    	echo do_shortcode( "[bp-shortcodes-profile user_id={$user->ID} group_id=2]" );
    
    	$shortcode_content = ob_get_clean();
    
    	return $content . $shortcode_content;
    } );
     
    
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2487
    Ravi on #40250

    Hello Tosin,

    I will recheck this code and will let you know.

    Regards
    Ravi

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2487
    Ravi on #40257

    Hello Tosin,

    I have checked and tested the code and it is working fine for me. Please check the following link:

    // User no details.
    https://tinyurl.com/ygtvoj56

    // User with details.
    https://tinyurl.com/yk5vtq8b

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 4
    Fabian on #44353

    Hey, I was looking for a similar way to help out members on a multi-member Buddypress website.
    is there a plugin that allows tips/donation to members similar to buy me coffee?
    I am not a developer, just a noob so if there is a plugin that would help me greatly. I dont mind paying for it.

  • Participant
    Level: Initiated
    Posts: 4
    Fabian on #44356

    Hi, I am a bit late to the game but better late than never 🙂
    Im trying to make a social community platform for creators and would like them to be able to receive donations/tips like for example “buy me a coffee”does.
    Is this possible on a buddypress website?
    I know its easy to set up a donatipn (PayPal or Stripe) for a single person but is it also possible for several members?
    Thank you so much 🙂

  • Keymaster
    (BuddyDev Team)
    Posts: 22166
    Brajesh Singh on #44357

    Hi Fabien,
    Thank you for the questions.

    You can easily achieve it.

    You can go though any of the following 2 methods:-

    — Easy way using xprofile field–
    1. Create a profile field and suggest users to use their donation link in it. Mark this field as private/only available to the user to avoid it being visible in their profile.
    2. Use xprofile_get_field_data() and show it as a button somewhere

    or
    — Adding a custom sub nav under settings —
    1. Add a screen under user account settings with a form field for their donation link
    2. User’s can specify their link and you may validate it
    3. Store it in user meta and use get_user_meta() to fetch and show it as button

    The first one is easy one but may not be very intuitive. The second seems more intuitive but will need a lot more code than the first.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved