Add Payment Method Column

Adds a custom "Payment Method" column to the WooCommerce orders table.

PHP
/**
 * 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
        }
    }
}

How To Implement This Solution?

Leave a Reply

Your email address will not be published. Required fields are marked *

My Agile Privacy
This site uses technical and profiling cookies. You can accept, decline or customize cookies by pressing the desired buttons. By closing this policy you will continue without accepting.

Need help?

Choose one of the following options:

Powered by CodingBunny