I'm using custom post types in the woocommerce checkout page - to add details of a car entering a race. The car fields are pulled from the CPT car's based on the user_id logged in user. The problem I am facing is the value is getting stored in the order rather than the text of the field. eg. Ford, Fiesta, 2001, black, what I am getting in the order is 488, 488, 488 etc
I am also storing the class the user is entering their car in - this too is showing correct on the front end - however storing the value in the back end. I've tried jquery/javascript - which I couldn't get to work. code:
<script type="text/javascript">
var car_text = $("#my_car_select option:selected").text();
$(function(){
$('select').change(function(){
$('select').val( $(this).val() );
var selectedText = $("#my_car_select")[0].textContent
})
})
$car_selected_name = $('#my_car_select:selected').text();
$("#my_car_select").change(function(){
var car_text = $("#my_car_select option:selected").text();
});
</script>
I've also tried to query the CPT based on the ID - however this doesn't work either, I keep getting an array, not just the field text.
I am very frustrated as the option text is on the screen on the front end just not getting stored on the backend - Something really simple which I can't figure out. Any help would be greatly appreciated. Thanks.
From what you have said it sounds like you just need to get the value from the selected option?
You almost have it right just need a space before :selected e.g
var selected_text = $('#my_car_select :selected').text();
Which should return the selected element.
Let me know if this is still causing any issues, might help to see the source of the element you need to fetch this from.