Barker Antony
Barker Antony

Reputation: 53

Woocommerce place order button script

I need to get the order id as a unique string type how do i do this? When an order is placed it is showing an order number e.g 2367 in admin

when i use this code

$order_id = str_pad($order_id, 4, '0', STR_PAD_LEFT); 

It shows as 0000.

Also how do I do an on Click event for the place order button on the checkout page to call a function.

Upvotes: 3

Views: 833

Answers (1)

Mahmudul Hassan
Mahmudul Hassan

Reputation: 51

You are getting 4 zeros as output because the first parameter $order_id in the str_pad() function is empty. So it is generating a string of length 4 with four zeros since you mentioned '0' in the 3rd parameter.

And for adding event to woocommerce place order button, you have to use a woocommerce hook. woocommerce_checkout_order_processed. Something like this you can use:

// define the woocommerce_checkout_order_processed callback 
function action_woocommerce_checkout_order_processed( $array ) { 
    // make action magic happen here... 
}; 

// add the action 
add_action( 'woocommerce_checkout_order_processed', 'action_woocommerce_checkout_order_processed', 10, 1 ); 

Upvotes: 1

Related Questions