3

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!

Rajesh Loganathan
  • 11,129
  • 4
  • 78
  • 90
MariaZ
  • 1,677
  • 9
  • 25
  • 41

2 Answers2

7

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.

  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/12479096) – Rajesh Loganathan May 27 '16 at 04:42
  • 1
    ok, I got your point. Hope now my answer looks more like an answer. –  May 27 '16 at 13:37
  • `woocommerce_checkout_order_processed` this is not working for me – mehmood khan Jun 02 '20 at 10:40
1
   ## I USED THIS CODE FOR ADDING DELIVERY CHARGES DEPENDING UPON THE CART SUBTOTAL AND SOME POST FIELDS ## 
function action_woocommerce_checkout_process($wccs_custom_checkout_field_pro_process ) 
    { 
            global $woocommerce;
            //Add Fuel Surcharge & CAF
            function woo_add_cart_fee() { 
            global $woocommerce;
            if ( WC()->cart->cart_contents_total < 1500 && 
                        $_POST['delivery_type']=='Pick Up') { 
                        $fuel_surchargeandCAF = get_option( 'fuel_surchargeandCAF', 
                        70 );
                        WC()->cart->add_fee( __('Delivery Charges', 'woocommerce'), 
                        $fuel_surchargeandCAF, TRUE, '');
                      }

                   }

    add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );


    }; 

    add_action( 'woocommerce_checkout_process', 'action_woocommerce_checkout_process', 10,

 1 );