• Resolved imthatguydavid

    (@imthatguydavid)


    I have created a memo section for the give plugin, but it doesn’t seems to appear in the wp-admin section.

    Was wondering if someone can look at what is wrong with my code.

    /**
     * Add Custom Donation Form Fields
     *
     * @param $form_id
     */ 
    function give_myprefix_custom_form_fields( $form_id ) {
    	// Only display for forms with the IDs "754" and "578";
    	// Remove "If" statement to display on all forms
    	// For a single form, use this instead:
    	// if ( $form_id == 754) {
    	$forms = array( 754, 578 ); ?>
    		<div id="give-memo-wrap">
    			<label class="give-label" for="give-memo"><?php _e( 'Memo:', 'give' ); ?>		<span class="give-tooltip icon icon-question" data-tooltip="<?php _e( 'Comment section for your donation', 'give' ) ?>"></span>
    			</label>
    			<textarea class="give-textarea" name="give_memo" id="give-memo"></textarea>
    		</div>
    	<?php 
    // endif; 
    } 
    
    add_action( 'give_after_donation_levels', 'give_myprefix_custom_form_fields', 10, 1 );
    
    /**
     * Add Field to Payment Meta
     *
     * Store the custom field data custom post meta attached to the <code>give_payment</code> CPT.
     *
     * @param $payment_id
     * @param $payment_data
     *
     * @return mixed
     */
    function myprefix123_give_donations_save_custom_fields( $payment_id, $payment_data ) {
          if ( isset( $_POST['give_memo'] ) ) {
    		$message = implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $_POST['give_memo'] ) ) );
    		add_post_meta( $payment_id, 'give_memo', $message );
    	}
    }
    
    add_action( 'give_insert_payment', 'myprefix123_give_donations_save_custom_fields', 10, 2 );
    
    /**
     * Show Data in Payment Details
     *
     * Show the custom field(s) on the payment details page in wp-admin
     *
     * @param $payment_id
     */
    function give_myprefix_purchase_details( $payment_id ) {
    	// Bounce out if no data for this transaction
    	$give_memo = give_get_meta( $payment_id, 'give_memo', true );
            if ( $give_memo ) : ?>
    	<div id="give-memo-details" class="postbox">
                <h3 class="hndle"><?php esc_html_e( 'Memo Message', 'give' ); ?></h3>
                <div class="inside" style="padding-bottom:10px;">
                    <?php echo wpautop( $give_memo ); ?>
                </div>
            </div>
    
            <?php endif;
     } 
    
    add_action( 'give_payment_personal_details_list', 'give_myprefix_purchase_details', 10, 2 );
    

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Matt Cromwell

    (@webdevmattcrom)

    In the last line of your code, change the action from give_payment_personal_details_list to give_view_donation_details_billing_before

    Let me know how that goes.

    Thread Starter imthatguydavid

    (@imthatguydavid)

    Thanks for the reply! didn’t seem to work.

    it’s still not showing up in wp-admin.

    Hey @imthatguydavid Kindly try this code and let me know if this is working for you or not

    /**
     * Add Custom Donation Form Fields
     *
     * @param $form_id
     */
    function give_myprefix_custom_form_fields( $form_id ) {
    	// Only display for forms with the IDs "754" and "578";
    	// Remove "If" statement to display on all forms
    	// For a single form, use this instead:
    	// if ( $form_id == 754) {
    	$forms = array( 754, 578 ); ?>
    	<div id="give-memo-wrap">
    		<label class="give-label" for="give-memo"><?php _e( 'Memo:', 'give' ); ?> <span
    				class="give-tooltip icon icon-question"
    				data-tooltip="<?php _e( 'Comment section for your donation', 'give' ) ?>"></span>
    		</label>
    		<textarea class="give-textarea" name="give_memo" id="give-memo"></textarea>
    	</div>
    	<?php
    // endif;
    }
    
    add_action( 'give_after_donation_levels', 'give_myprefix_custom_form_fields', 10, 1 );
    
    /**
     * Add Field to Payment Meta
     *
     * Store the custom field data custom post meta attached to the <code>give_payment</code> CPT.
     *
     * @param $payment_id
     * @param $payment_data
     *
     * @return mixed
     */
    function myprefix123_give_donations_save_custom_fields( $payment_id, $payment_data ) {
    	if ( isset( $_POST['give_memo'] ) ) {
    		$message = implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $_POST['give_memo'] ) ) );
    		give_update_meta( $payment_id, 'give_memo', $message );
    	}
    }
    
    add_action( 'give_insert_payment', 'myprefix123_give_donations_save_custom_fields', 10, 2 );
    
    /**
     * Show Data in Payment Details
     *
     * Show the custom field(s) on the payment details page in wp-admin
     *
     * @param $payment_id
     */
    function give_myprefix_purchase_details( $payment_meta ) {
    	$payment_id = absint( $_GET['id'] );
    
    	// Bounce out if no data for this transaction
    	$give_memo = give_get_meta( $payment_id, 'give_memo', true );
    
    	if ( $give_memo ) : ?>
    		<div id="give-memo-details" class="postbox">
    			<h3 class="hndle"><?php esc_html_e( 'Memo Message', 'give' ); ?></h3>
    			<div class="inside" style="padding-bottom:10px;">
    				<?php echo wpautop( $give_memo ); ?>
    			</div>
    		</div>
    
    	<?php endif;
    }
    
    add_action( 'give_payment_personal_details_list', 'give_myprefix_purchase_details', 10 );
    

    Thanks
    Deepak

    Thread Starter imthatguydavid

    (@imthatguydavid)

    Wow Thanks! Works perfectly!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding Memo Section for users’ is closed to new replies.