WC_API_Taxes::get_tax_classes()publicWC 2.5.0

Get all tax classes

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

Возвращает

Массив|WP_Error.

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

$WC_API_Taxes = new WC_API_Taxes();
$WC_API_Taxes->get_tax_classes( $fields );
$fields(строка)
-
По умолчанию: null

Список изменений

С версии 2.5.0 Введена.

Код WC_API_Taxes::get_tax_classes() WC 8.7.0

public function get_tax_classes( $fields = null ) {
	try {
		// Permissions check
		if ( ! current_user_can( 'manage_woocommerce' ) ) {
			throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_tax_classes', __( 'You do not have permission to read tax classes', 'woocommerce' ), 401 );
		}

		$tax_classes = array();

		// Add standard class
		$tax_classes[] = array(
			'slug' => 'standard',
			'name' => __( 'Standard rate', 'woocommerce' ),
		);

		$classes = WC_Tax::get_tax_classes();

		foreach ( $classes as $class ) {
			$tax_classes[] = apply_filters( 'woocommerce_api_tax_class_response', array(
				'slug' => sanitize_title( $class ),
				'name' => $class,
			), $class, $fields, $this );
		}

		return array( 'tax_classes' => apply_filters( 'woocommerce_api_tax_classes_response', $tax_classes, $classes, $fields, $this ) );
	} catch ( WC_API_Exception $e ) {
		return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
	}
}