WC_AJAX::create_product_with_attributes()private staticWC 1.0

Create product with attributes from POST data.

Method of the class: WC_AJAX{}

No Hooks.

Return

Mixed. Product class.

Usage

$result = WC_AJAX::create_product_with_attributes( $data );
$data(array) (required)
Attribute data.

WC_AJAX::create_product_with_attributes() code 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;
}