//WAREHUT: To enable international shipping, add this function to your functions.php file //Make sure that this function doesn't get erased during updates. //For any questions, please contact your customer service representative. function get_product_customs_details( $response, $object, $request ) { if ( empty( $response->data ) ) return $response; $products = $response->get_data(); foreach ( $products['line_items'] as $key => $productItem ) { $product_id = $productItem['product_id']; // Check if product ID is valid if ( ! empty( $product_id ) ) { $product = wc_get_product( $product_id ); // Check if product is valid if ( $product && ! is_wp_error( $product ) ) { // Add HS Codes to /orders API Requests $hs_code_attr = $product->get_attribute( 'hscode' ); $hs_code = ! empty( $hs_code_attr ) ? $hs_code_attr : ''; $response->data['line_items'][ $key ]['hs_code'] = $hs_code; // Add Country of Origin to /orders API Requests $country_of_origin_attr = $product->get_attribute( 'origin' ); $country_of_origin = ! empty( $country_of_origin_attr ) ? $country_of_origin_attr : ''; $response->data['line_items'][ $key ]['country_of_origin'] = $country_of_origin; // Add Weight to /orders API Requests $weight = $product->get_weight(); $response->data['line_items'][ $key ]['weight'] = $weight; } } } return $response; } add_filter( "woocommerce_rest_prepare_shop_order_object", "get_product_customs_details", 10, 3 );