WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WC_Admin_Importers::do_ajax_product_import() public WC 1.0

Ajax callback for importing one batch of products from a CSV.

Это метод класса: WC_Admin_Importers{}

Хуки из метода
Возвращает

Null. Ничего.

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

$WC_Admin_Importers = new WC_Admin_Importers();
$WC_Admin_Importers->do_ajax_product_import();

Код WC_Admin_Importers::do_ajax_product_import() WC 4.5.2

woocommerce/includes/admin/class-wc-admin-importers.php
<?php
public function do_ajax_product_import() {
	global $wpdb;

	check_ajax_referer( 'wc-product-import', 'security' );

	if ( ! $this->import_allowed() || ! isset( $_POST['file'] ) ) { // PHPCS: input var ok.
		wp_send_json_error( array( 'message' => __( 'Insufficient privileges to import products.', 'woocommerce' ) ) );
	}

	include_once WC_ABSPATH . 'includes/admin/importers/class-wc-product-csv-importer-controller.php';
	include_once WC_ABSPATH . 'includes/import/class-wc-product-csv-importer.php';

	$file   = wc_clean( wp_unslash( $_POST['file'] ) ); // PHPCS: input var ok.
	$params = array(
		'delimiter'       => ! empty( $_POST['delimiter'] ) ? wc_clean( wp_unslash( $_POST['delimiter'] ) ) : ',', // PHPCS: input var ok.
		'start_pos'       => isset( $_POST['position'] ) ? absint( $_POST['position'] ) : 0, // PHPCS: input var ok.
		'mapping'         => isset( $_POST['mapping'] ) ? (array) wc_clean( wp_unslash( $_POST['mapping'] ) ) : array(), // PHPCS: input var ok.
		'update_existing' => isset( $_POST['update_existing'] ) ? (bool) $_POST['update_existing'] : false, // PHPCS: input var ok.
		'lines'           => apply_filters( 'woocommerce_product_import_batch_size', 30 ),
		'parse'           => true,
	);

	// Log failures.
	if ( 0 !== $params['start_pos'] ) {
		$error_log = array_filter( (array) get_user_option( 'product_import_error_log' ) );
	} else {
		$error_log = array();
	}

	$importer         = WC_Product_CSV_Importer_Controller::get_importer( $file, $params );
	$results          = $importer->import();
	$percent_complete = $importer->get_percent_complete();
	$error_log        = array_merge( $error_log, $results['failed'], $results['skipped'] );

	update_user_option( get_current_user_id(), 'product_import_error_log', $error_log );

	if ( 100 === $percent_complete ) {
		// @codingStandardsIgnoreStart.
		$wpdb->delete( $wpdb->postmeta, array( 'meta_key' => '_original_id' ) );
		$wpdb->delete( $wpdb->posts, array(
			'post_type'   => 'product',
			'post_status' => 'importing',
		) );
		$wpdb->delete( $wpdb->posts, array(
			'post_type'   => 'product_variation',
			'post_status' => 'importing',
		) );
		// @codingStandardsIgnoreEnd.

		// Clean up orphaned data.
		$wpdb->query(
			"
			DELETE {$wpdb->posts}.* FROM {$wpdb->posts}
			LEFT JOIN {$wpdb->posts} wp ON wp.ID = {$wpdb->posts}.post_parent
			WHERE wp.ID IS NULL AND {$wpdb->posts}.post_type = 'product_variation'
		"
		);
		$wpdb->query(
			"
			DELETE {$wpdb->postmeta}.* FROM {$wpdb->postmeta}
			LEFT JOIN {$wpdb->posts} wp ON wp.ID = {$wpdb->postmeta}.post_id
			WHERE wp.ID IS NULL
		"
		);
		// @codingStandardsIgnoreStart.
		$wpdb->query( "
			DELETE tr.* FROM {$wpdb->term_relationships} tr
			LEFT JOIN {$wpdb->posts} wp ON wp.ID = tr.object_id
			LEFT JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
			WHERE wp.ID IS NULL
			AND tt.taxonomy IN ( '" . implode( "','", array_map( 'esc_sql', get_object_taxonomies( 'product' ) ) ) . "' )
		" );
		// @codingStandardsIgnoreEnd.

		// Send success.
		wp_send_json_success(
			array(
				'position'   => 'done',
				'percentage' => 100,
				'url'        => add_query_arg( array( '_wpnonce' => wp_create_nonce( 'woocommerce-csv-importer' ) ), admin_url( 'edit.php?post_type=product&page=product_importer&step=done' ) ),
				'imported'   => count( $results['imported'] ),
				'failed'     => count( $results['failed'] ),
				'updated'    => count( $results['updated'] ),
				'skipped'    => count( $results['skipped'] ),
			)
		);
	} else {
		wp_send_json_success(
			array(
				'position'   => $importer->get_file_position(),
				'percentage' => $percent_complete,
				'imported'   => count( $results['imported'] ),
				'failed'     => count( $results['failed'] ),
				'updated'    => count( $results['updated'] ),
				'skipped'    => count( $results['skipped'] ),
			)
		);
	}
}