WC_CSV_Exporter::format_data
Format and escape data ready for the CSV file.
Method of the class: WC_CSV_Exporter{}
No Hooks.
Returns
String.
Usage
$WC_CSV_Exporter = new WC_CSV_Exporter(); $WC_CSV_Exporter->format_data( $data );
- $data(string) (required)
- Data to format.
Changelog
| Since 3.1.0 | Introduced. |
WC_CSV_Exporter::format_data() WC CSV Exporter::format data code WC 10.3.5
public function format_data( $data ) {
if ( ! is_scalar( $data ) ) {
if ( is_a( $data, 'WC_Datetime' ) ) {
$data = $data->date( 'Y-m-d G:i:s' );
} else {
$data = ''; // Not supported.
}
} elseif ( is_bool( $data ) ) {
$data = $data ? 1 : 0;
}
$use_mb = function_exists( 'mb_convert_encoding' );
if ( $use_mb ) {
$is_valid_utf_8 = mb_check_encoding( $data, 'UTF-8' );
if ( ! $is_valid_utf_8 ) {
$data = mb_convert_encoding( $data, 'UTF-8', 'ISO-8859-1' );
}
}
return $this->escape_data( $data );
}