• Resolved Avinash Patel

    (@avinashdigitl)


    Hello, we have added custom code in our site, for when order is placed at that time we are storing custom data in woocommerce. However this is working until we have payment methods of “pay with card“, “PayPal” but when user pay with “Applepay” then none of this actions is triggering. So can someone suggest me correct hook that will always trigger in woocommerce when order is placed successfully with any payment method.

    add_action('woocommerce_checkout_order_processed', 'klaviyo_wc_checkout');
    
    add_action('woocommerce_thankyou', 'klaviyo_wc_checkout');

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi, woocommerce_checkout_order_processed is indeed the right hook. Have you tried to log the output of the function and its variables to catch where the fail point is?

    Alternatively, you could try these action hooks:

    woocommerce_checkout_create_order (@param $order, @param $data, @return void)

    or

    woocommerce_checkout_update_order_meta (@param $order_id, @param $data, @return void)

    First one fires just before $order_id = $order->save();.
    Second one fires just before woocommerce_checkout_order_processed.

    However, assuming you are trying to store user informations for marketing purpose (since I read a klaviyo-related function) my hypothesis is that whoever uses applepay is presumably using an apple device, hence is blocking by default a lot of marketing functions and what you are trying to store (klaviyo id maybe?) is simply not stored/blocked upstream.

    • This reply was modified 1 year, 7 months ago by techedge.
    Thread Starter Avinash Patel

    (@avinashdigitl)

    Hello, this hooks is not working when user pay with Applepay, is there any hook is available which we can use in woocommerce?

    Hello, I’ve already answered your question. Those hooks works as I said. What are you trying to achieve? Post at least some code or try to log the output of your functions and post it here, we can’t try to guess what’s happening.

    Thread Starter Avinash Patel

    (@avinashdigitl)

    Hello, so when someone pay using Applepay and do not return back into my site (order thank you page) then also i want to add some data /send email to customer. So is it possible to do with any woocommerce hook that will fire just after order is created in woocommerce.

    Ok, there is clearly a communication problem here. I’ve already told you which hooks could do what you need.

    woocommerce_checkout_create_order

    manipulates data JUST BEFORE order creation, while

    woocommerce_checkout_update_order_meta

    manipulates data JUST AFTER order creation.

    Specifically, the latter is used to add metas.

    If they don’t work it’s clearly a) your function fault or b) a default behaviour of apple pay. So I’m asking again, can you post your code so we can take a look at it? Have you logged the function steps? Does the function trigger but no data is saved? Or doesn’t the function trigger at all?

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @avinashdigitl

    The hooks you’re currently using, woocommerce_checkout_order_processed and woocommerce_thankyou, should technically be triggered after an order is placed, regardless of the payment method used. However, it’s possible that Apple Pay, being a direct payment method, might be bypassing the standard WooCommerce checkout process.

    To ensure that your custom code is triggered with Apple Pay, you could try using the woocommerce_payment_complete hook. This hook is triggered when WooCommerce marks an order as ‘completed’, which happens after successful payment, regardless of the payment method.

    Please note that you may have to adjust your function to work with this hook, as the woocommerce_payment_complete hook passes the order ID as an argument, not the order object.

    Additionally, you can also use the woocommerce_new_order hook, which is triggered when a new order is created. You can use this hook to add custom code that sends an email to the customer or adds data as you mentioned. Here’s a basic example of how you might use this hook:

    add_action( 'woocommerce_new_order', 'your_custom_function', 1, 1 );
    
    function your_custom_function( $order_id ) {
    // Your code here.
    }

    The woocommerce_new_order hook should be triggered when the order is created, even if the customer doesn’t return to the thank you page. So you should be able to use this hook to accomplish what you’re trying to do.

    Please note that this requires a good understanding of PHP and WordPress development. Unfortunately, custom coding is not something we can assist with directly. However, if you’re not comfortable with coding, you might want to hire a developer to help you with this.

    If you have any further questions on development or custom coding, don’t hesitate to reach out to some of our great resources available for support. Our WooCommerce community is brimming with skilled open-source developers who are active on the following channels:

    If you have any other questions or need further clarification, please don’t hesitate to ask.

    Thanks!

    Thread Starter Avinash Patel

    (@avinashdigitl)

    Hello, in woocommerce_new_order hook are we able to get order items, i think it is not possible?

    Hi there @avinashdigitl ??

    in woocommerce_new_order hook are we able to get order items, i think it is not possible?

    Just to note, with the custom function of the code you’d be able to call for the order items to be added in an email, for example, as the woocommerce_new_order is triggered when a new order is placed.

    I trust that points you in the right direction, but if you have more questions, let us know.

    We’re happy to help.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Which wc hook trigger to add custom data when order payment is complete?’ is closed to new replies.