WC_Product_CSV_Importer::get_formatting_callback()protectedWC 4.3.0

Get formatting callback.

Method of the class: WC_Product_CSV_Importer{}

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_formatting_callback();

Changelog

Since 4.3.0 Introduced.

WC_Product_CSV_Importer::get_formatting_callback() code WC 8.7.0

protected function get_formatting_callback() {

	/**
	 * Columns not mentioned here will get parsed with 'wc_clean'.
	 * column_name => callback.
	 */
	$data_formatting = array(
		'id'                => array( $this, 'parse_id_field' ),
		'type'              => array( $this, 'parse_comma_field' ),
		'published'         => array( $this, 'parse_published_field' ),
		'featured'          => array( $this, 'parse_bool_field' ),
		'date_on_sale_from' => array( $this, 'parse_datetime_field' ),
		'date_on_sale_to'   => array( $this, 'parse_datetime_field' ),
		'name'              => array( $this, 'parse_skip_field' ),
		'short_description' => array( $this, 'parse_description_field' ),
		'description'       => array( $this, 'parse_description_field' ),
		'manage_stock'      => array( $this, 'parse_bool_field' ),
		'low_stock_amount'  => array( $this, 'parse_stock_quantity_field' ),
		'backorders'        => array( $this, 'parse_backorders_field' ),
		'stock_status'      => array( $this, 'parse_bool_field' ),
		'sold_individually' => array( $this, 'parse_bool_field' ),
		'width'             => array( $this, 'parse_float_field' ),
		'length'            => array( $this, 'parse_float_field' ),
		'height'            => array( $this, 'parse_float_field' ),
		'weight'            => array( $this, 'parse_float_field' ),
		'reviews_allowed'   => array( $this, 'parse_bool_field' ),
		'purchase_note'     => 'wp_filter_post_kses',
		'price'             => 'wc_format_decimal',
		'regular_price'     => 'wc_format_decimal',
		'stock_quantity'    => array( $this, 'parse_stock_quantity_field' ),
		'category_ids'      => array( $this, 'parse_categories_field' ),
		'tag_ids'           => array( $this, 'parse_tags_field' ),
		'tag_ids_spaces'    => array( $this, 'parse_tags_spaces_field' ),
		'shipping_class_id' => array( $this, 'parse_shipping_class_field' ),
		'images'            => array( $this, 'parse_images_field' ),
		'parent_id'         => array( $this, 'parse_relative_field' ),
		'grouped_products'  => array( $this, 'parse_relative_comma_field' ),
		'upsell_ids'        => array( $this, 'parse_relative_comma_field' ),
		'cross_sell_ids'    => array( $this, 'parse_relative_comma_field' ),
		'download_limit'    => array( $this, 'parse_int_field' ),
		'download_expiry'   => array( $this, 'parse_int_field' ),
		'product_url'       => 'esc_url_raw',
		'menu_order'        => 'intval',
		'tax_status'        => array( $this, 'parse_tax_status_field' ),
	);

	/**
	 * Match special column names.
	 */
	$regex_match_data_formatting = array(
		'/attributes:value*/'    => array( $this, 'parse_comma_field' ),
		'/attributes:visible*/'  => array( $this, 'parse_bool_field' ),
		'/attributes:taxonomy*/' => array( $this, 'parse_bool_field' ),
		'/downloads:url*/'       => array( $this, 'parse_download_file_field' ),
		'/meta:*/'               => 'wp_kses_post', // Allow some HTML in meta fields.
	);

	$callbacks = array();

	// Figure out the parse function for each column.
	foreach ( $this->get_mapped_keys() as $index => $heading ) {
		$callback = 'wc_clean';

		if ( isset( $data_formatting[ $heading ] ) ) {
			$callback = $data_formatting[ $heading ];
		} else {
			foreach ( $regex_match_data_formatting as $regex => $callback ) {
				if ( preg_match( $regex, $heading ) ) {
					$callback = $callback;
					break;
				}
			}
		}

		$callbacks[] = $callback;
	}

	return apply_filters( 'woocommerce_product_importer_formatting_callbacks', $callbacks, $this );
}