Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

What I want is when an user checkout and go to paypal,befor payment and after checkout I want to insert some data in a database. I need a hook for that,I tried to use the hook

"woocommerce_checkout_process"

,but it's not giving correct result and showing old results.How do i solve it,if any other hook or any other process,please need help.

Below is my code in functions.php :

add_action('woocommerce_checkout_process', 'connect_woo_part');

function connect_woo_part()
{
    global $wpdb;
    global $woocommerce;

    $args = array(
    'post_type' => 'shop_order',
    'post_status' => 'publish',
    'meta_key' => '_customer_user',
    'posts_per_page' => '-1'
    );
$my_query = new WP_Query($args);
$customer_orders = $my_query->posts;

 foreach ($customer_orders as $customer_order) {
 $order = new WC_Order();

 $order->populate($customer_order);
 $orderdata[] =$order;
}

print_r($orderdata);
share|improve this question
    
Try looking in the class-wc-checkout.php file, you should see some potential hooks. –  helgatheviking Oct 24 '13 at 12:28
add comment

2 Answers

You need to have a hook which have the information of the current checkout.

Try to hook your function with this woocommerce_checkout_order_processed, it holds the current order_id

it is in line number 680 of classes/class-wc-checkout.php

and looks like this

do_action( 'woocommerce_checkout_order_processed', $order_id, $this->posted );

share|improve this answer
add comment

At this hook you don't have the order at the database yet, you will need a later hook like woocommerce_checkout_update_order_meta.

From class-wc-checkout.php, lines 384 & 385 (WooCommerce 2.1.2)

    // Let plugins add meta
    do_action( 'woocommerce_checkout_update_order_meta', $order_id, $this->posted );

That should give you all the data you want.

share|improve this answer
    
Hey Sudip Roy, did you solved your issue? Were any of the answers useful? Please let us know. Regards, Gabriel –  Gabriel Reguly Mar 2 at 0:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.