Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Add Payment Method to Custom Order Number in WooCommerce?

By customizing the order number to include the payment method, store owners can quickly and easily identify how each order was paid for. This means you no longer have to sift through detailed order information to find out which payment method a customer used at checkout. Now, let’s see how to incorporate the payment methods into the order IDs of an order.

Solution: Add Payment Method to Custom Order Number in WooCommerce

The code snippet adds the payment method to the order number based on the payment method used.

add_filter('woocommerce_order_number', 'ts_add_prefix_based_on_payment_method', 1, 2);

function ts_add_prefix_based_on_payment_method($order_id, $order) {
    // Get the payment method used for the order
    $payment_method = $order->get_payment_method();

    // Define prefix based on payment method
    $prefix = '';

    switch ($payment_method) {
        case 'paypal':
            $prefix = 'PAY-';
            break;
        case 'stripe':
            $prefix = 'STR-';
            break;
        case 'bacs': // Direct Bank Transfer
            $prefix = 'BACS-';
            break;
        case 'cod': // Cash on Delivery
            $prefix = 'COD-';
            break;
        case 'cheque': // Check Payment
            $prefix = 'CHK-';
            break;
        // Add more cases for other payment methods if needed
    }

    // Concatenate prefix with order id
    $new_order_number = $prefix . $order_id;

    return $new_order_number;
}

Output

Each order number is prefixed with an identifier based on the payment method used. For example, If cheque payment is used, the prefix ‘CHK-‘ is concatenated with the original order ID (123), resulting in the new order number ‘CHK-123’.

Add Payment Method to WooCommerce Order Numbers

Want to enhance the above customization by adding custom order numbers with customer details? Check out our post on including custom order numbers based on customer initials.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x