title: woocommerce_checkout_order_processed hook executing function twice
body: <p>I have attached a function to the <code>woocommerce_checkout_order_processed</code> hook:</p>
  <pre><code>//check if woocommerce is acive
  if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
      add_action('woocommerce_checkout_order_processed', 'wc_on_place_order');
  }
  </code></pre>
  <p>The <code>wc_on_place_order</code> function is to be executed after the user clicks on the <kbd>PLACE ORDER</kbd> button. However, it's so odd that the function is executed twice.</p>
  <p>My <code>wc_on_place_order</code> function calls an external api written in C#:</p>
  <pre><code>function wc_on_place_order( $order_id ) {
      global $wpdb;
  
      // get order object and order details
      $order = new WC_Order( $order_id ); 
      
      // get product details
      $items = $order-&gt;get_items();
      //return $items;
      
      $products = array();
      foreach ($items as $item) {
          array_push($products, 
              array('userid' =&gt; $order-&gt;user_id, 'descr' =&gt; $item['name'], 'amt' =&gt; (float)$item['line_total'])
          );
      }
  
      //passing $products to external api using `curl_exec`
      . . . .
  
      //on successful call, the page should be showing an `alert`, however, it does not
      // the handle response    
      if (strpos($response,'ERROR') !== false) {
              print_r($response);
      } else {
          echo &quot;&lt;script type='text/javascript'&gt;alert($response)&lt;/script&gt;&quot;;
      }
  }
  </code></pre>
  <p>After debugging on C# API, I noticed that it the service is being called twice, thus, the checkout is being saved twice to the API database.</p>
  <p>Is there something wrong with the <code>wc_on_place_order</code> function or is <code>woocommerce_checkout_order_processed</code> called twice when clicking the <kbd>PLACE ORDER</kbd>?</p>
  <p>Interestingly, adding <code>return $items</code> after <code>$items = $order-&gt;get_items()</code> somehow, the C# api was only called once:</p>
  <pre><code>// get product details
  $items = $order-&gt;get_items();
  return $items; //this line
  </code></pre>
  <p>Why is that so?</p>
  <p>One more question I would like to ask, is <code>woocommerce_checkout_order_processed</code> the right hook I should use? I have been searching the web for the correct hook to use and it seems that <code>woocommerce_checkout_order_processed</code> is used in the most post. I can't use the <code>woocommerce_thankyou</code> hook as it is also calling the API if I refresh the page.</p>
  <p>Any idea will be really appreciated.</p>
  <p><strong>EDIT:</strong></p>
  <blockquote>
  <p>I used <code>woocommerce_after_checkout_validation</code> hook which fires after pre-validations on checkout. I can't remember though why <code>woocommerce_checkout_order_processed</code> is being fired twice but I just changed some kind of settings in <code>WooCommerce</code> options page. I can't remember which.</p>
  </blockquote>
  <h2>Useful Links from the Comments:</h2>
  <ul>
  <li><a href="https://businessbloomer.com/woocommerce-visual-hook-guide-archiveshopcat-page/" rel="nofollow noreferrer">Visual Representation of the WooCommerce hooks</a></li>
  <li><a href="https://codex.wordpress.org/Plugin_API/Action_Reference" rel="nofollow noreferrer">WordPress Action References</a></li>
  </ul>