1
votes

I have a custom payment gateway plugin which i need to include a custom column in woocommerce order list will show transaction status from payment gateway. Is there any hook available to write this code inside the payment gateway plugin?

class WC_xxxxx_Gateway extends WC_Payment_Gateway {

  public function __construct() {
 add_filter( 'manage_edit-shop_order_columns', 'wc_new_order_column' );
    }

     public function wc_new_order_column($columns){
        $columns['my_column'] = 'transaction status';
        return $columns;
       } // no output

     }
1

1 Answers

0
votes

You can not add a column on admin orders list only for one payment method (gateway) and you don't need to extend WC_Payment_Gateway Class to add a custom column to admin orders list.

First just add the column for all payment gateways and what you can do is to customize the displayed values for each order, based on your custom payment method.

For that you need to find out the payment method id for your custom payment gateway (replacing in the code paypal, with the correct payment method id.

Then you can add the conditions in the 2nd function below, to display things as you want related to your custom payment gateway "status".

add_filter( 'manage_edit-shop_order_columns', 'payment_gateway_orders_column' );
function payment_gateway_orders_column( $columns ) {
    $new_columns = array();

    foreach ( $columns as $column_key => $column_label ) {
        if ( 'order_total' === $column_key ) {
            $new_columns['transaction_status'] = __('Transaction status', 'woocommerce');
        }

        $new_columns[$column_key] = $column_label;
    }
    return $new_columns;
}

add_action( 'manage_shop_order_posts_custom_column' , 'payment_gateway_orders_column_content' );
function payment_gateway_orders_column_content( $column ) {
    global $the_order, $post;

    // HERE below set your targeted payment method ID
    $payment_method_id = 'paypal';

    if( $column  == 'transaction_status' ) {
        if( $the_order->get_payment_method() === $payment_method_id ) {
            // HERE below you will add your code and conditions
            $output = 'some status';
        } else {
            $output = '-';
        }

        // Display
        echo '<div style="text-align:center;">' . $output . '</div>';
    }
}

Code goes in functions.php file of the active child theme (or active theme), or in a custom plugin file. tested and works.