0

The goal is to create a new order when a new user registers wordpress site. To achieve that, the following hook was added to child theme's functions.php.

add_action( 'user_register', 'add_order', 10, 1 );

    function add_order( $user_id ) {

        $order = wc_create_order();
        $order->set_customer_id($user_id);
        $order->save();
    }

However, when a new user registers, no new order is created. No error is seen in the log. Wondering how to achieve the goal correctly.

2
  • 1
    Please check your child theme is Working or not because your code is testing in my site it's working when reg. user get order in backed. Jul 10, 2017 at 8:14
  • hi, thanks. it's created in db, but not displayed in wp-admin->woocommerce->orders Jul 10, 2017 at 19:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.