A
A
Alexa_KyKi2021-01-30 17:45:07
WooCommerce
Alexa_KyKi, 2021-01-30 17:45:07

How to store ACF field value in WooCommerce order details?

There is a task: on the checkout page there are delivery methods, if a specific delivery method is selected (only 1), then a drop-down list should appear with the delivery time. This field is implemented using the ACF Repeater plugin and the field type is Text. What time the user has chosen, respectively, should be displayed in the order details in the Wookomers admin panel.

Based on the theme code that I got, I wrote the following:

1. In the woocommerce/checkout/form-shipping.php file, the following code:

<div id="delivery_times" class="form-group d-none">
   <label class="text-bold" for="select_time">Delivery time: </label>
      <select id="select_time" class="form-control mb-1">
         <option value="" selected>Select time</option>
         <?php
            $delivery_times = get_field('delivery_times', 'options');
            $count = 0;
            foreach ($delivery_times as $delivery_time):
              echo '<option value="'.$delivery_time['range_time'].'" data-pickup="'.$count.'">'.$delivery_time['range_time'].'</option>';
              $count++;
            endforeach;
          ?>
       </select>
</div>


2. There is a common theme-checkout.js file, I added the following to it:
$("#shipping_speed").change(function(){
    var delivery_time = $(this).children("option:selected").data("type");

    if(delivery_time == "tomorrow"){
       $("#delivery_times").removeClass("d-none");
    }else{
       $("#delivery_times").addClass("d-none");
       $("#select_time option[value='']").prop('selected',true);
    }
});


And now I need to save the selected data and display them somehow in the order details for the administrator, but I have not found the implementation of something similar in my theme. Can you please tell me how can I transfer this data from the ACF field to the order details?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question