Support » Plugin: WooCommerce » Action when submiting checkout form

  • Hello guys !

    I’m searching about execute a piece of code after when customers submit the checkout form to buy a product.
    I’ve try differents conditions like :

    • when $_POST[‘my button name’] is set
    • many hooks

    To be clear, my goal is get and then store customer billing informations (from the checkout form) and use these data later in the function(s) called.

    So i need you to explain me the good way to do it. I’m here for any question !

Viewing 5 replies - 1 through 5 (of 5 total)
  • Caleb Burks


    Automattic Happiness Engineer

    > my goal is get and then store customer billing informations

    This is already done for you, and the data is stored as postmeta for the order.

    You can use one of these hooks to execute your code every time an order is submitted though:

    Hey Caleb,

    Sorry this is not my goal, in fact i’ve already rode data with this (for exemple) :

    $customer_id = get_current_user_id();
    get_user_meta( $customer_id, 'billing_phone', true );

    I just need the condition to execute my functions when user has submitted the checkout form, to store the actual value. If I get and store in another file before the customer submit the checkout form, informations may be false.

    I would like to know how export customer informations 🙂

    Thanks a lot !

    Caleb Burks


    Automattic Happiness Engineer

    There’s isn’t a conditional to use for this – that wouldn’t work anyways.

    You need to hook your functions onto a hook that gets executed when a customer goes through checkout. I linked to two above.

    Hey Caleb, i’m really newbie with woocommerce/wordpress and these hooks !

    So i understand the utility but i’m not able to call correctly any hook.

    I’ve test some pieces of code like this to test if it’s working :

    function zero_export_customers_data($this_id) {
    	// header( 'Location:' );
    	$customer_id = get_current_user_id();
    	print get_user_meta( $customer_id, 'billing_phone', true );

    I’ve test with and without function’s parameter*

    And these lines to add the function to the hook / filter you told me to use.

    add_filter('woocommerce_payment_complete_order_status', 'zero_export_customers_data');
    add_action('woocommerce_payment_complete', 'zero_export_customers_data');

    Can you explain me how it works / the way to execute my function at the right time, please.

    Thanks !

    [ No bumping please. ]

    Caleb Burks


    Automattic Happiness Engineer

    Both are action hooks, so you shouldn’t have one as a filter. The parameter is going to be the order ID, and your first hook need to have the order status attached to the end like this: woocommerce_payment_complete_order_status_completed.

    Secondly, these hooks are triggered by the payment gateway I believe. Maybe this is better for your need:

    The customer ID is already stored in the order object by the way. It’s stored as order meta with the key of customer_user.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Action when submiting checkout form’ is closed to new replies.