WC_AJAX::add_attributes_and_variations()public staticWC 1.0

Save attributes and variations via ajax.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$result = WC_AJAX::add_attributes_and_variations();

Код WC_AJAX::add_attributes_and_variations() WC 8.9.3

public static function add_attributes_and_variations() {
	check_ajax_referer( 'add-attributes-and-variations', 'security' );

	if ( ! current_user_can( 'edit_products' ) || ! isset( $_POST['data'], $_POST['post_id'] ) ) {
		wp_die( -1 );
	}

	try {
		parse_str( wp_unslash( $_POST['data'] ), $data ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized

		$product = self::create_product_with_attributes( $data );
		self::create_all_product_variations( $product );

		wp_send_json_success();
		wp_die();

	} catch ( Exception $e ) {
		wp_send_json_error( array( 'error' => $e->getMessage() ) );
	}
}