I am trying to insert the $addresscustom to the Woocommerce REST API, but it displays the Error:
> I/flutter (19003): FormatException: Unexpected character (at character 1)
> I/flutter (19003): <style type="text/css"> .wp-die-message {display: none; }
> I/flutter (19003): ^
Why it is saying the response is not json decoded (Flutter FormatException: Unexpected character (at character 1)), when it is indeed decoded? For instance, when I use the code 2, it works and displays the URL in the REST API:
The code:
function get_address_store( $response, $order_obj, $request, $object) {
if( empty( $response->data ) )
return $response;
$order = WC_Order( $order_obj->get_order_number() );
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item['product_id'];
$itemdata = $item->get_data();
$item_id = $itemdata['id'];
}
$gift_wrap = wc_get_order_item_meta( $item_id, 'anbieter',true);
$vendor_data_new = get_page_by_title($gift_wrap, '', 'wpsl_stores');
$addresscustom = get_post_meta( $vendor_data_new->ID, 'wpsl_address', true );
$response->data['line_items'][0]['store_address'] = $addresscustom;
return $response;
}
add_filter( "woocommerce_rest_prepare_shop_order_object","get_address_store", 10, 3 );
Code 2 (working):
function get_product_order_image( $response, $object, $request ) {
if( empty( $response->data ) )
return $response;
$order_pid= $response->data['line_items'][0]['product_id'];
$l_w_product_meta = get_post_meta($order_pid);
$order_imgUrl= wp_get_attachment_url( $l_w_product_meta['_thumbnail_id'][0], 'full' );
$response->data['line_items'][0]['cover_image'] = $order_imgUrl;
return $response;
}
add_filter( "woocommerce_rest_prepare_shop_order_object","get_product_order_image", 10, 3 );
Thanks for taking a time to read it :)