Answer the question
In order to leave comments, you need to log in
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>
$("#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);
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question