WordPress at Your Fingertips
function is not described

WC_API_Taxes::create_tax_class() public WC 2.5.0

Create a tax class.

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

Hooks from the method
Return

Array|WP_Error.

Usage

$WC_API_Taxes = new WC_API_Taxes();
$WC_API_Taxes->create_tax_class( $data );
$data(array) (required)
-

Changelog

Since 2.5.0 Introduced.

Code of WC_API_Taxes::create_tax_class() WC 5.6.0

public function create_tax_class( $data ) {
	try {
		if ( ! isset( $data['tax_class'] ) ) {
			throw new WC_API_Exception( 'woocommerce_api_missing_tax_class_data', sprintf( __( 'No %1$s data specified to create %1$s', 'woocommerce' ), 'tax_class' ), 400 );
		}

		// Check permissions
		if ( ! current_user_can( 'manage_woocommerce' ) ) {
			throw new WC_API_Exception( 'woocommerce_api_user_cannot_create_tax_class', __( 'You do not have permission to create tax classes', 'woocommerce' ), 401 );
		}

		$data = $data['tax_class'];

		if ( empty( $data['name'] ) ) {
			throw new WC_API_Exception( 'woocommerce_api_missing_tax_class_name', sprintf( __( 'Missing parameter %s', 'woocommerce' ), 'name' ), 400 );
		}

		$name      = sanitize_text_field( $data['name'] );
		$tax_class = WC_Tax::create_tax_class( $name );

		if ( is_wp_error( $tax_class ) ) {
			return new WP_Error( 'woocommerce_api_' . $tax_class->get_error_code(), $tax_class->get_error_message(), 401 );
		}

		do_action( 'woocommerce_api_create_tax_class', $tax_class['slug'], $data );

		$this->server->send_status( 201 );

		return array(
			'tax_class' => $tax_class,
		);
	} catch ( WC_API_Exception $e ) {
		return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
	}
}