• Resolved TechMan

    (@techman)


    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

    (@techman)

    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

    (@shameemreza)

    Hi @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 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

    (@techman)

    What is the hook for after order has been confirmed?

    Plugin Support Shameem – a11n

    (@shameemreza)

    Hello @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

    (@techman)

    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.

    Hi @techman

    This is a bit of a complicated topic that would need some customization to address. Unfortunately, custom coding 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:

    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.