Adding a hook to "Place order" button in woocommerce

MariaZ picture MariaZ · Jan 8, 2016 · Viewed 24.1k times · Source

When the user gets to the checkout, there is a button , the "Place order" button at the bottom of the form. I have been trying to add a hook to this button in woocommerce, but I don't seem to find the correct one, I have tried woocommerce_checkout_place_order... but it doesnt do anything.

function my_function() {
  //write function
}

add_action( "woocommerce_order_status_pending", "my_function");

Thanks in advance!

Answer

user6360285 picture user6360285 · May 26, 2016

You need this hook woocommerce_review_order_after_submit. It will execute any function you hook to it just after the submit area. with this hook you can add some html on the checkout page after the submit button. But if you need to call a function after the user have pressed the "Place order" button - use woocommerce_checkout_order_processed. This one will hook you just after the order was created so you can use the freshly generated order details:

add_action( 'woocommerce_checkout_order_processed', 'is_express_delivery',  1, 1  );
function is_express_delivery( $order_id ){

   $order = new WC_Order( $order_id );
   //something else

}

You may check this site for some more hooks you might use on the checkout page.