WC_API_Taxes::delete_tax()publicWC 2.5.0

Delete a tax

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

Хуков нет.

Возвращает

Массив|WP_Error.

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

$WC_API_Taxes = new WC_API_Taxes();
$WC_API_Taxes->delete_tax( $id );
$id(int) (обязательный)
The tax ID

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

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

Код WC_API_Taxes::delete_tax() WC 8.7.0

public function delete_tax( $id ) {
	global $wpdb;

	try {
		// Check permissions
		if ( ! current_user_can( 'manage_woocommerce' ) ) {
			throw new WC_API_Exception( 'woocommerce_api_user_cannot_delete_tax', __( 'You do not have permission to delete tax rates', 'woocommerce' ), 401 );
		}

		$id = absint( $id );

		WC_Tax::_delete_tax_rate( $id );

		if ( 0 === $wpdb->rows_affected ) {
			throw new WC_API_Exception( 'woocommerce_api_cannot_delete_tax', __( 'Could not delete the tax rate', 'woocommerce' ), 401 );
		}

		return array( 'message' => sprintf( __( 'Deleted %s', 'woocommerce' ), 'tax' ) );
	} catch ( WC_API_Exception $e ) {
		return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
	}
}