WordPress at Your Fingertips
function is not described

WC_AJAX::add_new_attribute() public WC 1.0

Add a new attribute via ajax function.

{} It's a method of the class: WC_AJAX{}

No Hooks.

Return

null. Nothing.

Usage

$result = WC_AJAX::add_new_attribute();

Code of WC_AJAX::add_new_attribute() WC 5.9.0

public static function add_new_attribute() {
	check_ajax_referer( 'add-attribute', 'security' );

	if ( current_user_can( 'manage_product_terms' ) && isset( $_POST['taxonomy'], $_POST['term'] ) ) {
		$taxonomy = esc_attr( wp_unslash( $_POST['taxonomy'] ) ); // phpcs:ignore
		$term     = wc_clean( wp_unslash( $_POST['term'] ) );

		if ( taxonomy_exists( $taxonomy ) ) {

			$result = wp_insert_term( $term, $taxonomy );

			if ( is_wp_error( $result ) ) {
				wp_send_json(
					array(
						'error' => $result->get_error_message(),
					)
				);
			} else {
				$term = get_term_by( 'id', $result['term_id'], $taxonomy );
				wp_send_json(
					array(
						'term_id' => $term->term_id,
						'name'    => $term->name,
						'slug'    => $term->slug,
					)
				);
			}
		}
	}
	wp_die( -1 );
}