title: How to pass a data array from one hooked function to another in WooCommerce
body: <p>I am doing a call to a partner API using the data contained in woocommerce checkout fields as well as the cart. This first call is made using the checkout process hook to validate the data through the API. if the call returns that it is valid the process goes on, otherwise it stops.</p>
  <p>I then need to wait for the payment to be complete to do another call to actually create a plan using the exact same data. Is there a way to pass the array i create in the first call in the checkout process hook to the payment complete hook in order to not have to rebuild the array?</p>
  <p>The code would look as follows:</p>
  <pre><code>add_action('woocommerce_checkout_process', 'apicall_verif');  
  function apicall_verif() {
      $_ids      = array(...);
  
      $billing_fields = [
        'billing_first_name'  =&gt; '',
        'billing_last_name'   =&gt; '',
        'billing_email'       =&gt; '',
        'billing_phone'       =&gt; '',
        'insurance-birthdate' =&gt; '',
        'gender-selection'    =&gt; '',
          'billing_address_1' =&gt; '',
          'billing_address_2' =&gt; '',
          'billing_postcode'  =&gt; '',
          'billing_city'      =&gt; ''  
      ];
      
      foreach( $fields as $field_name =&gt; $value ) {
          if( !empty( $_POST[$field_name] ) ) {
              $fields[$field_name] = sanitize_text_field( $_POST[$field_name] );
          } 
      }
       
      foreach ( WC()-&gt;cart-&gt;get_cart() as $cart_item ) {
          if ( in_array( $cart_item['product_id'],  $_ids ) ) {
              $_product_id = $cart_item['product_id'];
          }
      }
      
      $_product       =  wc_get_product( $_product_id );
      $billingcountry = WC()-&gt;customer-&gt;get_billing_country();
      $cur_lang       = pll_current_language();
      
      $data_verif = array(
          &quot;refs&quot;         =&gt;  array(
              &quot;country&quot;  =&gt; $billingcountry,
          ),
          &quot;settings&quot;     =&gt;  array(
              &quot;language&quot; =&gt; $cur_lang
          ),
          &quot;policyholder&quot; =&gt;  array(
              &quot;firstName&quot;  =&gt; $fields['billing_first_name'] ,
              &quot;lastName&quot;   =&gt; $fields['billing_last_name'],
              &quot;email&quot;      =&gt; $fields['billing_email'],
              &quot;phone&quot;      =&gt; $fields['billing_phone'],
              &quot;birthdate&quot;  =&gt; $fields['insurance-birthdate'],
              &quot;gender&quot;     =&gt; $fields['gender-selection' ],
              &quot;address&quot;    =&gt;  array(
                  &quot;country&quot;  =&gt; $billingcountry,
                  &quot;zip&quot;      =&gt; $fields['billing_postcode'],
                  &quot;city&quot;     =&gt; $fields['billing_city'],
                  &quot;street&quot;   =&gt; $fields['billing_address_1'],
                  &quot;number&quot;   =&gt; $fields['billing_address_2'],
                  &quot;box&quot;      =&gt; &quot;box&quot;
              ),
              &quot;entityType&quot; =&gt; &quot;ENTITY_TYPE_PERSON&quot;
          ), 
          &quot;risk&quot;         =&gt; array(
               &quot;model&quot;            =&gt; $_product -&gt; get_title(),
               &quot;originalValue&quot;    =&gt;  $_product -&gt; get_price() * 100,
               &quot;antiTheftMeasure&quot; =&gt; &quot;ANTI_THEFT_MEASURE_NONE&quot;,
          ),
          &quot;terms&quot;        =&gt; array(
              &quot;depreciation&quot; =&gt; false
          ),
      );
      
      // Set the array to a custom WC_Session variable (to be used afterwards)
      WC()-&gt;session-&gt;set('data_verif', $data_verif);
      
      // API CALL HERE AND CHECK WHETHER VALID OR NOT
  }
  
  
  //After payment is completed
  add_action( 'woocommerce_payment_complete', 'apicall_create' );
  function apicall_create() {
      //Somehow get $data_verif here and do another API call
  }
  </code></pre>