Title: Incorrect payment method when reading order data using PHP
Last modified: November 2, 2023

---

# Incorrect payment method when reading order data using PHP

 *  Resolved [TechMan](https://wordpress.org/support/users/techman/)
 * (@techman)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/incorrect-payment-method-when-reading-order-data-using-php/)
 * I am using following code to read payment method and send custom notification
   to customer.
 * `$order = new WC_Order( $order_id );
   $payment_method = $order->get_payment_method_title();
 * For some reason, just now a customer placed order and its detail was incorrectly
   read as “Credit/Debit Card” when in fact she chose “Cash on delivery”. It has
   worked fine before and even after that but for this particular order, wrong information
   was picked. I don’t know how that can happen.
 * One thing I noticed that this order no. is 18932 and last time someone placed
   order using Credit/Debit Card, that order no. was 18923. Notice the similarity
   between the two!? I don’t know how it can somehow read wrong data because order
   no. is similar, but this is only weird thing I was able to find.

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [TechMan](https://wordpress.org/support/users/techman/)
 * (@techman)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/incorrect-payment-method-when-reading-order-data-using-php/#post-17170498)
 * Ok I talked to customer and found out what exactly happened and was able to recreate
   it.
 * She first chose Credit/Debit Card as payment method, after which notification
   was sent to her as it fired `woocommerce_new_order` hook. But she pressed back
   button on browser and changed method to Cash on delivery.
 *  Plugin Support [Shameem – a11n](https://wordpress.org/support/users/shameemreza/)
 * (@shameemreza)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/incorrect-payment-method-when-reading-order-data-using-php/#post-17178420)
 * Hi [@techman](https://wordpress.org/support/users/techman/)
 * From your explanation, it looks like the issue occurred because the customer 
   initially chose “Credit/Debit Card” as the payment method, triggering the `woocommerce_new_order`
   hook and sending the notification. When she used the browser’s back button to
   change her payment method to “Cash on Delivery”, the hook had already been triggered,
   and the notification was sent, hence the discrepancy.
 * The similarity in the order numbers is likely coincidental and shouldn’t affect
   the payment method data.
 * To prevent this issue from happening in the future, you might need to consider
   triggering the notification at a later point in the checkout process, such as
   after the order has been confirmed, to ensure that the correct payment method
   is captured in the notification.
 * Alternatively, you can use the [AutomateWoo](https://woo.com/products/automatewoo/)
   plugin instead of using custom code to send customized notifications based on
   various conditions and workflow.
 * I hope this provides some clarity. Please let us know if you have any other questions!
 *  Thread Starter [TechMan](https://wordpress.org/support/users/techman/)
 * (@techman)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/incorrect-payment-method-when-reading-order-data-using-php/#post-17178516)
 * What is the hook for after order has been confirmed?
 *  Plugin Support [Shameem – a11n](https://wordpress.org/support/users/shameemreza/)
 * (@shameemreza)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/incorrect-payment-method-when-reading-order-data-using-php/#post-17182977)
 * Hello [@techman](https://wordpress.org/support/users/techman/),
 * You can use the `woocommerce_thankyou` for triggering an action after an order
   has been confirmed. This hook is triggered after the order has been processed
   and the thank you/confirmation page is displayed to the customer.
 * I hope this helps! If you have any more questions, feel free to ask.
 *  Thread Starter [TechMan](https://wordpress.org/support/users/techman/)
 * (@techman)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/incorrect-payment-method-when-reading-order-data-using-php/#post-17194420)
 * There is a slight problem with using **woocommerce_thankyou** hook for notification.
   If a customer opens thank you page again or refresh the page then it will again
   send a notification. So basically, every time customer opens/refreshes thank 
   you page, it sends that custom notification that your order has been received.
 *  [xue28 (woo-hc)](https://wordpress.org/support/users/xue28/)
 * (@xue28)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/incorrect-payment-method-when-reading-order-data-using-php/#post-17199754)
 * Hi [@techman](https://wordpress.org/support/users/techman/)
 * This is a bit of a complicated topic that would need some customization to address.
   Unfortunately, [custom coding](https://woocommerce.com/support-policy/) is not
   something we can assist with directly. However, I’ll keep this thread open for
   a bit to see if anyone from the community can lend a hand.
 * If you have any other questions related to development or custom coding, don’t
   hesitate to reach out to some of the great resources we have available for support.
   The WooCommerce community is filled with talented open-source developers, and
   many of them are active on the channels listed below:
    - [WooCommerce Developer Resources Portal](https://developer.woocommerce.com/)
    - [WooCommerce Advanced Facebook group](https://www.facebook.com/groups/advanced.woocommerce/)
    - [WooCommerce Developer Slack Channel](https://woocommerce.com/community-slack/)
    - Hire a [WooCommerce Expert](https://woocommerce.com/experts/)
 * Hope this helps!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Incorrect payment method when reading order data using PHP’ is closed
to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 6 replies
 * 3 participants
 * Last reply from: [xue28 (woo-hc)](https://wordpress.org/support/users/xue28/)
 * Last activity: [2 years, 6 months ago](https://wordpress.org/support/topic/incorrect-payment-method-when-reading-order-data-using-php/#post-17199754)
 * Status: resolved