Hook and send Woocommerce data after click Place Order button

I’m finding the way to add a hook to my woo commerce check out page (http://localhost/checkout) I’m tend to send cart items and billing address, user information to another page such as http://localhost/hooking after clicking Place Order button for more further purpose, is it possible, and how to do it?

1 Answer
1

For this three possibilities:

If you really want to do it on order place you would have to use the hook:

woocommerce_new_order

However I would recommend you use the hook:

woocommerce_order_status_completed

This would make sure that the order is finished when you send then information.

To catch the information before billing you could always use:

woocommerce_before_checkout_billing_form

If this still isn’t working you could check the hook list:

https://docs.woocommerce.com/wc-apidocs/hook-docs.html

You then would simply have something like:

add_action( 'woocommerce_order_status_completed', 'wc_send_order_to_mypage' );
function wc_send_order_to_mypage( $order_id ) {
$shipping_add = [
            "firstname" => $order->shipping_first_name,
            "lastname" => $order->shipping_last_name,
            "address1" => $order->shipping_address_1,
            "address2" => $order->shipping_address_2,
            "city" => $order->shipping_city,
            "zipcode" => $order->shipping_postcode,
            "phone" => $order->shipping_phone,
            "state_name" => $order->shipping_state,
            "country" => $order->shipping_country
        ];
//from $order you can get all the item information etc 
//above is just a simple example how it works
//your code to send data
}

Since the ultimate goal is to have your own payment system I would recommend you check out this tutorial that explains how to integrate your own payment gateway

How to Create a Simple WooCommerce Payment Gateway

Leave a Comment