admin管理员组

文章数量:1122832

I want to get the form-fields on checkout page when the user clicks on place-order button.

For this I tried different hooks, but the control does not even enter into mine block of code

I'm using the following.

add_action('woocommerce_checkout_process', 'custom_process_order');
function custom_process_order(){

   //do some your magic here
   print_r( WC()->checkout()->get_posted_data() );
   exit();
}

With this code, I got nothing.

I have checked this and this, but no success.

How can I get all the form fields when place-order buttons is clicked.

Note:

I don't want to get them via js or JQuery to get the fields data, I want to use proper hook for this.

I want to get the form-fields on checkout page when the user clicks on place-order button.

For this I tried different hooks, but the control does not even enter into mine block of code

I'm using the following.

add_action('woocommerce_checkout_process', 'custom_process_order');
function custom_process_order(){

   //do some your magic here
   print_r( WC()->checkout()->get_posted_data() );
   exit();
}

With this code, I got nothing.

I have checked this and this, but no success.

How can I get all the form fields when place-order buttons is clicked.

Note:

I don't want to get them via js or JQuery to get the fields data, I want to use proper hook for this.

Share Improve this question edited Jun 2, 2020 at 14:10 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Jun 2, 2020 at 12:01 mehmoodmehmood 11 silver badge2 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The place-order form button is actually called woocommerce_checkout_place_order, and the code in WC_Form_Handler passes this on to WC_Checkout process_checkout().

Here's the relevant code. You probably want to hook:

  • woocommerce_before_checkout_process or woocommerce_checkout_process, which happen before this code reads the items from posted data itself (although you could call WC()->checkout()->get_posted_data() yourself I think)
  • woocommerce_after_checkout_validation, which is passed the posted data as its first argument along with an errors array
  • woocommerce_checkout_order_processed if you want the data after the checkout is complete.

本文标签: pluginsHow to get the checkout form data from checkout page when placeorder button is clicked