WC_AJAX::create_product_with_attributes()private staticWC 1.0

Create product with attributes from POST data.

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

Хуков нет.

Возвращает

Разное. Product class.

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

$result = WC_AJAX::create_product_with_attributes( $data );
$data(массив) (обязательный)
Attribute data.

Код WC_AJAX::create_product_with_attributes() WC 8.7.0

private static function create_product_with_attributes( $data ) {
	// phpcs:disable WordPress.Security.NonceVerification.Missing
	if ( ! isset( $_POST['post_id'] ) ) {
		wp_die( -1 );
	}
	$attributes   = WC_Meta_Box_Product_Data::prepare_attributes( $data );
	$product_id   = absint( wp_unslash( $_POST['post_id'] ) );
	$product_type = ! empty( $_POST['product_type'] ) ? wc_clean( wp_unslash( $_POST['product_type'] ) ) : 'simple';
	$classname    = WC_Product_Factory::get_product_classname( $product_id, $product_type );
	$product      = new $classname( $product_id );
	$product->set_attributes( $attributes );
	$product->save();
	return $product;
}