/**
* Snippet Name: Add Payment Method Column
* Snippet Author: coding-bunny.com
* Description: Adds a custom "Payment Method" column to the WooCommerce orders table.
*/
// Add a custom column to the WooCommerce orders table
add_filter('manage_edit-shop_order_columns', 'cb_add_payment_method_column');
function cb_add_payment_method_column($columns) {
$columns['cb_payment_method'] = __('Payment Method', 'cb'); // Add "Payment Method" column
return $columns;
}
// Populate the custom "Payment Method" column with data
add_action('manage_shop_order_posts_custom_column', 'cb_display_payment_method_column');
function cb_display_payment_method_column($column) {
global $post;
if ('cb_payment_method' === $column) {
$order = wc_get_order($post->ID); // Get the order object
if ($order) {
// Output the payment method title with escaping for security
echo esc_html($order->get_payment_method_title());
} else {
echo esc_html('-'); // Placeholder if the order object is invalid
}
}
}
Add Payment Method Column
Adds a custom "Payment Method" column to the WooCommerce orders table.