WC_Product_CSV_Importer::get_formatting_callback │ protected │ WC 4.3.0

Get formatting callback.

Метод класса: WC_Product_CSV_Importer{}

Возвращает

array.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_formatting_callback();

Список изменений

С версии 4.3.0 Введена.

Код WC_Product_CSV_Importer::get_formatting_callback() WC 11.2.2

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' ),
		'cogs_value'        => array( $this, 'parse_cogs_field' ),
	);

	/**
	 * Match special column names by prefix.
	 *
	 * These prefixes must stay in sync with the `starts_with()` checks in `expand_data()`,
	 * which is what decides how the column is actually consumed. Matching anywhere in the
	 * column name instead of at the start would apply a formatting callback to columns
	 * `expand_data()` never treats as special.
	 */
	$prefix_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' ),
		// Allow some HTML in meta fields.
		'meta:'               => 'wp_kses_post',
	);

	$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 ( $prefix_match_data_formatting as $prefix => $prefix_callback ) {
				if ( $this->starts_with( $heading, $prefix ) ) {
					$callback = $prefix_callback;
					break;
				}
			}
		}

		$callbacks[] = $callback;
	}

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