1

我有一个自定义支付网关插件,我需要在 woocommerce 订单列表中包含一个自定义列,以显示来自支付网关的交易状态。是否有任何钩子可用于在支付网关插件中编写此代码?

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

     }
4

1 回答 1

0

不能只为一种付款方式(网关)在管理订单列表中添加一列,并且您不需要扩展WC_Payment_GatewayClass 以将自定义列添加到管理订单列表。

首先,只需添加所有支付网关的列,您可以根据您的自定义支付方式自定义每个订单的显示值。

为此,您需要找出自定义支付网关的支付方式 ID(在代码paypal中替换为正确的支付方式 ID。

然后您可以在下面的第二个函数中添加条件,以显示与您的自定义支付网关“状态”相关的内容。

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>';
    }
}

代码位于活动子主题(或活动主题)的 functions.php 文件中,或位于自定义插件文件中。测试和工作。

于 2019-08-20T15:14:11.377 回答