MariaZ
MariaZ

Reputation: 1747

Adding a hook to "Place order" button in woocommerce

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!

Upvotes: 3

Views: 33614

Answers (2)

Akshay More
Akshay More

Reputation: 56

   ## 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 ); 

Upvotes: 2

user6360285
user6360285

Reputation:

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.

Upvotes: 7

Related Questions