您不能只为一种付款方式(网关)在管理订单列表中添加一列,并且您不需要扩展WC_Payment_Gateway
Class 以将自定义列添加到管理订单列表。
首先,只需添加所有支付网关的列,您可以根据您的自定义支付方式自定义每个订单的显示值。
为此,您需要找出自定义支付网关的支付方式 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 文件中,或位于自定义插件文件中。测试和工作。