Capture custom checkout field value in Woocommerce












1















Im on woocommerce and are trying by snipets, get the value of all fields to send to adroid app with json.



The trouble its, that i cant capture the values of custom fields on check out. I tried by plugin and snippet create the field but, i cant recover the values to send to json



the field was created with that snipet



add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );

function my_custom_checkout_field( $checkout ) {

echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';

woocommerce_form_field( 'my_field_name', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Fill in this field'),
'placeholder' => __('Enter something'),
), $checkout->get_value( 'my_field_name' ));

echo '</div>';

}


when try to create the json with that snipet i can get all standard woo values but i cant get the custom field



function action_woocommerce_order_status_completed( $array ) { 

$order = wc_get_order( $order_id );
$url = 'localhost/wp/recolector.php';

//Initiate cURL.
$ch = curl_init($url);

// now you can get the data from $product array
};

//The JSON data.
$jsonData = array(
'email' => $order->get_billing_email(),
'first_name'=> $order->get_billing_first_name(),
'last_name' => $order->get_billing_last_name(),
'phone'=>$order->get_billing_phone()(),
'address'=>$order->get_billing_address_1(),
'city'=>$order->get_billing_city(),
'province'=>$order->get_billing_state(),
'country'=>$order->get_billing_country(),
'order'=>$order->get_order_number()
);

//Encode the array into JSON.
$jsonDataEncoded = json_encode($jsonData);

//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);

//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

//Execute the request
$result = curl_exec($ch);


};

// add the action
add_action( 'woocommerce_order_status_completed', 'action_woocommerce_order_status_completed', 10, 1 );


well how supose can add my_field_name to json?



Thanks for help.










share|improve this question





























    1















    Im on woocommerce and are trying by snipets, get the value of all fields to send to adroid app with json.



    The trouble its, that i cant capture the values of custom fields on check out. I tried by plugin and snippet create the field but, i cant recover the values to send to json



    the field was created with that snipet



    add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );

    function my_custom_checkout_field( $checkout ) {

    echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';

    woocommerce_form_field( 'my_field_name', array(
    'type' => 'text',
    'class' => array('my-field-class form-row-wide'),
    'label' => __('Fill in this field'),
    'placeholder' => __('Enter something'),
    ), $checkout->get_value( 'my_field_name' ));

    echo '</div>';

    }


    when try to create the json with that snipet i can get all standard woo values but i cant get the custom field



    function action_woocommerce_order_status_completed( $array ) { 

    $order = wc_get_order( $order_id );
    $url = 'localhost/wp/recolector.php';

    //Initiate cURL.
    $ch = curl_init($url);

    // now you can get the data from $product array
    };

    //The JSON data.
    $jsonData = array(
    'email' => $order->get_billing_email(),
    'first_name'=> $order->get_billing_first_name(),
    'last_name' => $order->get_billing_last_name(),
    'phone'=>$order->get_billing_phone()(),
    'address'=>$order->get_billing_address_1(),
    'city'=>$order->get_billing_city(),
    'province'=>$order->get_billing_state(),
    'country'=>$order->get_billing_country(),
    'order'=>$order->get_order_number()
    );

    //Encode the array into JSON.
    $jsonDataEncoded = json_encode($jsonData);

    //Tell cURL that we want to send a POST request.
    curl_setopt($ch, CURLOPT_POST, 1);

    //Attach our encoded JSON string to the POST fields.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

    //Set the content type to application/json
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

    //Execute the request
    $result = curl_exec($ch);


    };

    // add the action
    add_action( 'woocommerce_order_status_completed', 'action_woocommerce_order_status_completed', 10, 1 );


    well how supose can add my_field_name to json?



    Thanks for help.










    share|improve this question



























      1












      1








      1


      1






      Im on woocommerce and are trying by snipets, get the value of all fields to send to adroid app with json.



      The trouble its, that i cant capture the values of custom fields on check out. I tried by plugin and snippet create the field but, i cant recover the values to send to json



      the field was created with that snipet



      add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );

      function my_custom_checkout_field( $checkout ) {

      echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';

      woocommerce_form_field( 'my_field_name', array(
      'type' => 'text',
      'class' => array('my-field-class form-row-wide'),
      'label' => __('Fill in this field'),
      'placeholder' => __('Enter something'),
      ), $checkout->get_value( 'my_field_name' ));

      echo '</div>';

      }


      when try to create the json with that snipet i can get all standard woo values but i cant get the custom field



      function action_woocommerce_order_status_completed( $array ) { 

      $order = wc_get_order( $order_id );
      $url = 'localhost/wp/recolector.php';

      //Initiate cURL.
      $ch = curl_init($url);

      // now you can get the data from $product array
      };

      //The JSON data.
      $jsonData = array(
      'email' => $order->get_billing_email(),
      'first_name'=> $order->get_billing_first_name(),
      'last_name' => $order->get_billing_last_name(),
      'phone'=>$order->get_billing_phone()(),
      'address'=>$order->get_billing_address_1(),
      'city'=>$order->get_billing_city(),
      'province'=>$order->get_billing_state(),
      'country'=>$order->get_billing_country(),
      'order'=>$order->get_order_number()
      );

      //Encode the array into JSON.
      $jsonDataEncoded = json_encode($jsonData);

      //Tell cURL that we want to send a POST request.
      curl_setopt($ch, CURLOPT_POST, 1);

      //Attach our encoded JSON string to the POST fields.
      curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

      //Set the content type to application/json
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

      //Execute the request
      $result = curl_exec($ch);


      };

      // add the action
      add_action( 'woocommerce_order_status_completed', 'action_woocommerce_order_status_completed', 10, 1 );


      well how supose can add my_field_name to json?



      Thanks for help.










      share|improve this question
















      Im on woocommerce and are trying by snipets, get the value of all fields to send to adroid app with json.



      The trouble its, that i cant capture the values of custom fields on check out. I tried by plugin and snippet create the field but, i cant recover the values to send to json



      the field was created with that snipet



      add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );

      function my_custom_checkout_field( $checkout ) {

      echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';

      woocommerce_form_field( 'my_field_name', array(
      'type' => 'text',
      'class' => array('my-field-class form-row-wide'),
      'label' => __('Fill in this field'),
      'placeholder' => __('Enter something'),
      ), $checkout->get_value( 'my_field_name' ));

      echo '</div>';

      }


      when try to create the json with that snipet i can get all standard woo values but i cant get the custom field



      function action_woocommerce_order_status_completed( $array ) { 

      $order = wc_get_order( $order_id );
      $url = 'localhost/wp/recolector.php';

      //Initiate cURL.
      $ch = curl_init($url);

      // now you can get the data from $product array
      };

      //The JSON data.
      $jsonData = array(
      'email' => $order->get_billing_email(),
      'first_name'=> $order->get_billing_first_name(),
      'last_name' => $order->get_billing_last_name(),
      'phone'=>$order->get_billing_phone()(),
      'address'=>$order->get_billing_address_1(),
      'city'=>$order->get_billing_city(),
      'province'=>$order->get_billing_state(),
      'country'=>$order->get_billing_country(),
      'order'=>$order->get_order_number()
      );

      //Encode the array into JSON.
      $jsonDataEncoded = json_encode($jsonData);

      //Tell cURL that we want to send a POST request.
      curl_setopt($ch, CURLOPT_POST, 1);

      //Attach our encoded JSON string to the POST fields.
      curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

      //Set the content type to application/json
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

      //Execute the request
      $result = curl_exec($ch);


      };

      // add the action
      add_action( 'woocommerce_order_status_completed', 'action_woocommerce_order_status_completed', 10, 1 );


      well how supose can add my_field_name to json?



      Thanks for help.







      php wordpress woocommerce custom-fields orders






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 21:06









      LoicTheAztec

      94.3k1369108




      94.3k1369108










      asked Nov 21 '18 at 19:01









      Arucard7sArucard7s

      82




      82
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Updated



          There are some mistakes and missing things in your code. Try the following instead:



          // Display a custom checkout field
          add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
          function my_custom_checkout_field( $checkout ) {
          echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';

          woocommerce_form_field( '_custom_field', array(
          'type' => 'text',
          'class' => array('my-custom-field form-row-wide'),
          'label' => __('Fill in this field'),
          'placeholder' => __('Enter something'),
          ), $checkout->get_value( '_custom_field' ));

          echo '</div>';
          }

          // Save the custom checkout field in the order meta
          add_action( 'woocommerce_checkout_create_order', 'save_order_custom_meta_data', 10, 2 );
          function save_order_custom_meta_data( $order, $data ) {
          if ( isset($_POST['_custom_field']) )
          $order->update_meta_data('_custom_field', sanitize_text_field( $_POST['_custom_field'] ) );
          }


          add_action( 'woocommerce_order_status_completed', 'action_on_order_status_completed', 10, 2 );
          function action_on_order_status_completed( $order_id, $order ) {
          // The order data (array)
          $data = array(
          'email' => $order->get_billing_email(),
          'first_name' => $order->get_billing_first_name(),
          'last_name' => $order->get_billing_last_name(),
          'phone' => $order->get_billing_phone()(),
          'address' => $order->get_billing_address_1(),
          'city' => $order->get_billing_city(),
          'province' => $order->get_billing_state(),
          'country' => $order->get_billing_country(),
          'order' => $order->get_order_number()
          );

          // Get the custom field value (and add it if not empty)
          if( $custom_field = $order->get_meta('_custom_field') ) {
          // Add it to the array
          $data['custom_field'] = $custom_field;
          }

          //Encode the array into JSON.
          $json_data = json_encode( $data );

          // The Url
          $url = 'localhost/wp/recolector.php';

          //Initiate cURL.
          $ch = curl_init($url);

          //Tell cURL that we want to send a POST request.
          curl_setopt($ch, CURLOPT_POST, 1);

          //Attach our encoded JSON string to the POST fields.
          curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

          //Set the content type to application/json
          curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

          //Execute the request
          $result = curl_exec($ch);

          // Set the return result in the order as custom meta data (if needed)
          $order->update_meta_data('_curl_result', $result );
          $order->save();
          }


          It should better work now.






          share|improve this answer


























          • Thanks for help , but when try to use your code php response that: Fixed malformed JSON. Original: checkout.min.js:1:9459 test de pruebaArray ( [custom_field] => test de prueba ) <br />

            – Arucard7s
            Nov 22 '18 at 0:39













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418918%2fcapture-custom-checkout-field-value-in-woocommerce%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Updated



          There are some mistakes and missing things in your code. Try the following instead:



          // Display a custom checkout field
          add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
          function my_custom_checkout_field( $checkout ) {
          echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';

          woocommerce_form_field( '_custom_field', array(
          'type' => 'text',
          'class' => array('my-custom-field form-row-wide'),
          'label' => __('Fill in this field'),
          'placeholder' => __('Enter something'),
          ), $checkout->get_value( '_custom_field' ));

          echo '</div>';
          }

          // Save the custom checkout field in the order meta
          add_action( 'woocommerce_checkout_create_order', 'save_order_custom_meta_data', 10, 2 );
          function save_order_custom_meta_data( $order, $data ) {
          if ( isset($_POST['_custom_field']) )
          $order->update_meta_data('_custom_field', sanitize_text_field( $_POST['_custom_field'] ) );
          }


          add_action( 'woocommerce_order_status_completed', 'action_on_order_status_completed', 10, 2 );
          function action_on_order_status_completed( $order_id, $order ) {
          // The order data (array)
          $data = array(
          'email' => $order->get_billing_email(),
          'first_name' => $order->get_billing_first_name(),
          'last_name' => $order->get_billing_last_name(),
          'phone' => $order->get_billing_phone()(),
          'address' => $order->get_billing_address_1(),
          'city' => $order->get_billing_city(),
          'province' => $order->get_billing_state(),
          'country' => $order->get_billing_country(),
          'order' => $order->get_order_number()
          );

          // Get the custom field value (and add it if not empty)
          if( $custom_field = $order->get_meta('_custom_field') ) {
          // Add it to the array
          $data['custom_field'] = $custom_field;
          }

          //Encode the array into JSON.
          $json_data = json_encode( $data );

          // The Url
          $url = 'localhost/wp/recolector.php';

          //Initiate cURL.
          $ch = curl_init($url);

          //Tell cURL that we want to send a POST request.
          curl_setopt($ch, CURLOPT_POST, 1);

          //Attach our encoded JSON string to the POST fields.
          curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

          //Set the content type to application/json
          curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

          //Execute the request
          $result = curl_exec($ch);

          // Set the return result in the order as custom meta data (if needed)
          $order->update_meta_data('_curl_result', $result );
          $order->save();
          }


          It should better work now.






          share|improve this answer


























          • Thanks for help , but when try to use your code php response that: Fixed malformed JSON. Original: checkout.min.js:1:9459 test de pruebaArray ( [custom_field] => test de prueba ) <br />

            – Arucard7s
            Nov 22 '18 at 0:39


















          1














          Updated



          There are some mistakes and missing things in your code. Try the following instead:



          // Display a custom checkout field
          add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
          function my_custom_checkout_field( $checkout ) {
          echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';

          woocommerce_form_field( '_custom_field', array(
          'type' => 'text',
          'class' => array('my-custom-field form-row-wide'),
          'label' => __('Fill in this field'),
          'placeholder' => __('Enter something'),
          ), $checkout->get_value( '_custom_field' ));

          echo '</div>';
          }

          // Save the custom checkout field in the order meta
          add_action( 'woocommerce_checkout_create_order', 'save_order_custom_meta_data', 10, 2 );
          function save_order_custom_meta_data( $order, $data ) {
          if ( isset($_POST['_custom_field']) )
          $order->update_meta_data('_custom_field', sanitize_text_field( $_POST['_custom_field'] ) );
          }


          add_action( 'woocommerce_order_status_completed', 'action_on_order_status_completed', 10, 2 );
          function action_on_order_status_completed( $order_id, $order ) {
          // The order data (array)
          $data = array(
          'email' => $order->get_billing_email(),
          'first_name' => $order->get_billing_first_name(),
          'last_name' => $order->get_billing_last_name(),
          'phone' => $order->get_billing_phone()(),
          'address' => $order->get_billing_address_1(),
          'city' => $order->get_billing_city(),
          'province' => $order->get_billing_state(),
          'country' => $order->get_billing_country(),
          'order' => $order->get_order_number()
          );

          // Get the custom field value (and add it if not empty)
          if( $custom_field = $order->get_meta('_custom_field') ) {
          // Add it to the array
          $data['custom_field'] = $custom_field;
          }

          //Encode the array into JSON.
          $json_data = json_encode( $data );

          // The Url
          $url = 'localhost/wp/recolector.php';

          //Initiate cURL.
          $ch = curl_init($url);

          //Tell cURL that we want to send a POST request.
          curl_setopt($ch, CURLOPT_POST, 1);

          //Attach our encoded JSON string to the POST fields.
          curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

          //Set the content type to application/json
          curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

          //Execute the request
          $result = curl_exec($ch);

          // Set the return result in the order as custom meta data (if needed)
          $order->update_meta_data('_curl_result', $result );
          $order->save();
          }


          It should better work now.






          share|improve this answer


























          • Thanks for help , but when try to use your code php response that: Fixed malformed JSON. Original: checkout.min.js:1:9459 test de pruebaArray ( [custom_field] => test de prueba ) <br />

            – Arucard7s
            Nov 22 '18 at 0:39
















          1












          1








          1







          Updated



          There are some mistakes and missing things in your code. Try the following instead:



          // Display a custom checkout field
          add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
          function my_custom_checkout_field( $checkout ) {
          echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';

          woocommerce_form_field( '_custom_field', array(
          'type' => 'text',
          'class' => array('my-custom-field form-row-wide'),
          'label' => __('Fill in this field'),
          'placeholder' => __('Enter something'),
          ), $checkout->get_value( '_custom_field' ));

          echo '</div>';
          }

          // Save the custom checkout field in the order meta
          add_action( 'woocommerce_checkout_create_order', 'save_order_custom_meta_data', 10, 2 );
          function save_order_custom_meta_data( $order, $data ) {
          if ( isset($_POST['_custom_field']) )
          $order->update_meta_data('_custom_field', sanitize_text_field( $_POST['_custom_field'] ) );
          }


          add_action( 'woocommerce_order_status_completed', 'action_on_order_status_completed', 10, 2 );
          function action_on_order_status_completed( $order_id, $order ) {
          // The order data (array)
          $data = array(
          'email' => $order->get_billing_email(),
          'first_name' => $order->get_billing_first_name(),
          'last_name' => $order->get_billing_last_name(),
          'phone' => $order->get_billing_phone()(),
          'address' => $order->get_billing_address_1(),
          'city' => $order->get_billing_city(),
          'province' => $order->get_billing_state(),
          'country' => $order->get_billing_country(),
          'order' => $order->get_order_number()
          );

          // Get the custom field value (and add it if not empty)
          if( $custom_field = $order->get_meta('_custom_field') ) {
          // Add it to the array
          $data['custom_field'] = $custom_field;
          }

          //Encode the array into JSON.
          $json_data = json_encode( $data );

          // The Url
          $url = 'localhost/wp/recolector.php';

          //Initiate cURL.
          $ch = curl_init($url);

          //Tell cURL that we want to send a POST request.
          curl_setopt($ch, CURLOPT_POST, 1);

          //Attach our encoded JSON string to the POST fields.
          curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

          //Set the content type to application/json
          curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

          //Execute the request
          $result = curl_exec($ch);

          // Set the return result in the order as custom meta data (if needed)
          $order->update_meta_data('_curl_result', $result );
          $order->save();
          }


          It should better work now.






          share|improve this answer















          Updated



          There are some mistakes and missing things in your code. Try the following instead:



          // Display a custom checkout field
          add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
          function my_custom_checkout_field( $checkout ) {
          echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';

          woocommerce_form_field( '_custom_field', array(
          'type' => 'text',
          'class' => array('my-custom-field form-row-wide'),
          'label' => __('Fill in this field'),
          'placeholder' => __('Enter something'),
          ), $checkout->get_value( '_custom_field' ));

          echo '</div>';
          }

          // Save the custom checkout field in the order meta
          add_action( 'woocommerce_checkout_create_order', 'save_order_custom_meta_data', 10, 2 );
          function save_order_custom_meta_data( $order, $data ) {
          if ( isset($_POST['_custom_field']) )
          $order->update_meta_data('_custom_field', sanitize_text_field( $_POST['_custom_field'] ) );
          }


          add_action( 'woocommerce_order_status_completed', 'action_on_order_status_completed', 10, 2 );
          function action_on_order_status_completed( $order_id, $order ) {
          // The order data (array)
          $data = array(
          'email' => $order->get_billing_email(),
          'first_name' => $order->get_billing_first_name(),
          'last_name' => $order->get_billing_last_name(),
          'phone' => $order->get_billing_phone()(),
          'address' => $order->get_billing_address_1(),
          'city' => $order->get_billing_city(),
          'province' => $order->get_billing_state(),
          'country' => $order->get_billing_country(),
          'order' => $order->get_order_number()
          );

          // Get the custom field value (and add it if not empty)
          if( $custom_field = $order->get_meta('_custom_field') ) {
          // Add it to the array
          $data['custom_field'] = $custom_field;
          }

          //Encode the array into JSON.
          $json_data = json_encode( $data );

          // The Url
          $url = 'localhost/wp/recolector.php';

          //Initiate cURL.
          $ch = curl_init($url);

          //Tell cURL that we want to send a POST request.
          curl_setopt($ch, CURLOPT_POST, 1);

          //Attach our encoded JSON string to the POST fields.
          curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

          //Set the content type to application/json
          curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

          //Execute the request
          $result = curl_exec($ch);

          // Set the return result in the order as custom meta data (if needed)
          $order->update_meta_data('_curl_result', $result );
          $order->save();
          }


          It should better work now.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 22 '18 at 0:51

























          answered Nov 21 '18 at 20:15









          LoicTheAztecLoicTheAztec

          94.3k1369108




          94.3k1369108













          • Thanks for help , but when try to use your code php response that: Fixed malformed JSON. Original: checkout.min.js:1:9459 test de pruebaArray ( [custom_field] => test de prueba ) <br />

            – Arucard7s
            Nov 22 '18 at 0:39





















          • Thanks for help , but when try to use your code php response that: Fixed malformed JSON. Original: checkout.min.js:1:9459 test de pruebaArray ( [custom_field] => test de prueba ) <br />

            – Arucard7s
            Nov 22 '18 at 0:39



















          Thanks for help , but when try to use your code php response that: Fixed malformed JSON. Original: checkout.min.js:1:9459 test de pruebaArray ( [custom_field] => test de prueba ) <br />

          – Arucard7s
          Nov 22 '18 at 0:39







          Thanks for help , but when try to use your code php response that: Fixed malformed JSON. Original: checkout.min.js:1:9459 test de pruebaArray ( [custom_field] => test de prueba ) <br />

          – Arucard7s
          Nov 22 '18 at 0:39






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418918%2fcapture-custom-checkout-field-value-in-woocommerce%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to change which sound is reproduced for terminal bell?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Can I use Tabulator js library in my java Spring + Thymeleaf project?