You can use the below code in your child theme’s functions.php file, you will get “Extra product options” field details in REST API product response with the key “wepo_options“.
add_filter( 'woocommerce_rest_prepare_product_object', 'wc_app_add_custom_data_to_product', 10, 3 );
add_filter( 'woocommerce_rest_prepare_product_variation_object', 'wc_app_add_custom_data_to_product', 20, 3 );
// filter the product response here
function wc_app_add_custom_data_to_product( $response, $post, $request ) {
$product_id = $post->get_id();
$sections = display_fields_in_front_end($product_id);
$response->data['thwepof_options'] = $sections;
}
function display_fields_in_front_end($product_id){
$all_sections = array();
$product = wc_get_product($product_id);
$product_type = $product->get_type();
$categories = THWEPOF_Utils::get_product_categories($product_id);
$tags = THWEPOF_Utils::get_product_tags($product_id);
$sections = THWEPOF_Utils::get_sections();
$section_fields = array();
if($sections && is_array($sections) && !empty($sections)){
foreach($sections as $section_name => $section){
$section = THWEPOF_Utils_Section::get_fields($section);
$all_sections[] = $section;
}
}
return $all_sections;
}
Please be informed that in the case of our extra product options plugin, the product page is rendering all extra product option fields. Then while clicking the add to cart button, it takes the extra product option data and stores it on a key named as?thwepof_options?in the cart. You can use this method on your app.
However, there are some limitations in WooCommerce to add additional product options to the cart using API.?
Hope this helps.