3

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?

2
  • The best would be to do it on order completed
    – Mederic
    Commented Jan 22, 2018 at 3:34
  • Cus I have another payment method, which need Woocommerce cart items to start paying. @@. Very confusing stuff @@. Thank for responding, @Mederic. Commented Jan 22, 2018 at 3:41

1 Answer 1

3

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

https://www.skyverge.com/blog/how-to-create-a-simple-woocommerce-payment-gateway/

5
  • How about using this hook: woocommerce_review_order_after_submit . The problem is, my localhost/hooking is a php page, I've tried putting some code like global $woocommerce; $items = $woocommerce->cart->get_cart(); function process_payment($order_id) { $order = new WC_Order($order_id); return array('result' => 'success', 'redirect' => $order->get_checkout_payment_url( true )); } but it seem doesn't work Commented Jan 22, 2018 at 3:49
  • The code I gave you should be in a plugin or in the functions.php of your theme and in that function wc_send_order_to_mypage you make a post request to your php page for instance
    – Mederic
    Commented Jan 22, 2018 at 3:56
  • Thank you, but how can I get the item list and bring it to mypage ? Commented Jan 22, 2018 at 4:01
  • If you dont know how to make a redirection in php you shouldn't be coding something like this. check this: skyverge.com/blog/…
    – Mederic
    Commented Jan 22, 2018 at 4:03
  • Yahh, iI'll check that out, thank for you help, mate. Thank a lot !!!!. Commented Jan 22, 2018 at 4:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.