Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Devin Walker

    (@dlocc)

    Hi Kells,

    Hold on let me get my thinking cap on. Ok, it’s on. Here we go… First create the column like so:

    /**
     * Display a custom transaction column label
     *
     * @description: Adds a custom column to the transactions page; IMPROTANT: RENAME THIS FUNCTION TO SOMETHING CUSTOM TO YOUR SITE; you can rename the column to whatever data you want to appear within
     * @return array
     */
    function give_my_custom_tranactions_column( $columns ) {
    
    	$columns['my_column'] = __( 'My Column', 'sometextdomain' );
    
    	return $columns;
    }
    
    add_filter( 'give_payments_table_columns', 'give_my_custom_tranactions_column' );
    

    Then, output your custom field data into the column like so:

    /**
     * Custom Transaction Column Data
     *
     * @description: Display data within your custom column
     *
     * @param $value
     * @param $payment_id
     * @param $column_name
     *
     * @return mixed
     */
    function my_payment_column_data( $value, $payment_id, $column_name ) {
    	if ( $column_name == 'my_column' ) {
    
    		//output any custom data here
    		echo 'Hello World';
    
    	}
    
    	return $value;
    }
    
    add_filter( 'give_payments_table_column', 'my_payment_column_data', 10, 3 );
    

    Take notice of the functions descriptions. Specifically, renamne the functions so if this is more widely used in the future you don’t run into any fatal errors.

    Please review and let me know if you have anymore questions! Oh and… thanks for using Give!

    just wonder where should the php code be placed ? Function.php of the theme or any template ?

    Thanks
    Alfred

    Plugin Author Matt Cromwell

    (@webdevmattcrom)

    HI Alfred,

    CUstom PHP code like this really should be in a custom functionality plugin so that you don’t lose that functionality when you switch themes.

    We have a guide on doing that here:
    https://givewp.com/documentation/resources/adding-custom-functions-to-your-wordpress-website/

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post custom field into transaction column’ is closed to new replies.